I need to execute this mysql query in MySQLi PDO with bind parametr in PHP:
mysql_query("INSERT INTO `posts` (post_name,publish_date) VALUES ($post_name,NOW()) ")
I use the script like this, but it doesn't insert publish_date correctly.
$publish_date = 'NOW()';
$insert = $mysqli->prepare("INSERT INTO posts (post_name,publish_date) VALUES (?,?)");
$insert->bind_param("ss", $post_name $publish_date);
$insert->execute();
It inserts the record into the publish_date
column like this: 0000-00-00 00:00:00
How can I do this ? Thanks in advance.
P.S: The type of date column is datatime
.
The PHP bind_param() function is used to bind variables to a prepared statement, as parameters, in PHP MySQLi object-oriented style.
Using the PHP MySQL to MySQLi Migration PackagePHP MySQL to MySQLi is package that emulates the mysql extension functions using the mysqli extension. It uses these replacement code solutions and can act as a stop-gap while you work on migrating your code.
The mysqli_num_rows() function returns the number of rows in a result set.
Probably you should try using the date function not NOW()
$publish_date =date("Y-m-d H:i:s");
$insert = $mysqli->prepare("INSERT INTO posts (post_name,publish_date) VALUES (?,?)");
$insert->bind_param("ss", $post_name $publish_date);
$insert->execute();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With