First of all, this is my first meeting with MySQLi... I heard that MySQLi is better, but every time I wrote some code, I get
Fatal error: Call to a member function bind_param() on a non-object
My code is this:
<?php
/* Create a new mysqli object with database connection parameters */
$m = new mysqli('localhost', 'root', '', 'mysqlisample');
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
$ida=1;
$statement = $m->prepare("SELECT * FROM post WHERE `id` = ?");
$statement->bind_param("i",$ida);
$id = 0;
$post_title = '';
$post_content = '';
$statement->bind_result($id,$post_title,$post_content);
$statement->execute();
while ($statement->fetch()){
echo $id.' '.$post_title.' '.$post_content.'\n'; //These variables will get the values of the current row
}
?>
This is just one of many code sample that I read somewhere, but, none of them working.
What is the right way for executing MySQLi query and print the results?