I am trying to do this:
$sth = $dbi->prepare('INSERT INTO table VALUES (?, ?, ?)'); $sth->execute( $var1, $var2 || 'NOW()', $var3 );
no luck. Any ideas?
$sth = $dbi->prepare('INSERT INTO table VALUES (?, COALESCE(?, NOW()), ?)'); $sth->execute( $var1, $var2, $var3 );
Functions cannot be related parameters. MySQL will enclose them in quotation marks, which is not a valid syntax.
Your options:
$now = time2str('%Y-%m-%d %T', time);
You can also use the following encoding.
$sth = $dbi->prepare('INSERT INTO table VALUES (?, COALESCE(?, NOW()), ?)'); $sth->bind_param($var1,$var2,$var3); $sth1=$sth->execute;