I'm learning about MySQL prepare statement and when I run the following code, I get the PHP Fatal error: Uncaught Error: Call to undefined function mysql_close(). The output is correct and I just can't figure out why such an error occurs. Thanks for your time!
$conn3 = new mysqli(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME);
$event_type = $jarray['event_type'];
$key = "submission";
$search = $conn3->prepare("SELECT * FROM metadb USE INDEX(field_id) WHERE event_type = ? AND event_field = ?");
$search->bind_param('ss', $event_type, $key);
$search->execute();
$search->store_result();
echo $search->num_rows;
mysql_close($conn3);
Use $conn3->close();
instead of mysql_close($conn3);
You are using mysqli
to open connection and then trying to close connection using mysql
.
Suggestion : You are mixing mysqli
object oriented and procedural in your code I will suggest you to stick with one(preferably Object Oriented). I will also suggest you to start using PDO
instead of mysqli
. reason explained here
For more detailed information about mysqli
you can refer this documentation.
For more detailed information about PDO
you can refer this documentation.