1

i am trying to create a database with the help of prepared statement as shown in this code but it gives me this error Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\backend.php on line 14 , i know it is giving false condition but why ? how to create the database with prepared statement.

<?php
$conn=new mysqli("127.0.0.1","rfasdfsdaosafasdfot","adsfasdggjhgasgda");
if($conn->connect_error){
echo "there is a error in the connection";
}else{
echo "there is no error in the connection";
 }
//$sql="create database mandi;";//this statement is correct by syntax.
//if($conn->query($sql)===true){
 //echo "database created";
 //}
$pre=$conn->prepare("create database ?");
$pre->bind_param("s",$hh);
$hh="bamo";
$pre->execute();
$pre->close();
$conn->close();
echo("all done");
?>
  • `Call to a member function bind_param() on boolean` From the docs: "mysqli_prepare() returns a statement object or _FALSE if an error occurred_." (emphasis mine). Put those two together and it should be clear what the problem is. – Patrick Q Oct 28 '16 at 12:45
  • Possible duplicate of [Can I parameterize the table name in a prepared statement?](http://stackoverflow.com/questions/11312737/can-i-parameterize-the-table-name-in-a-prepared-statement) – Patrick Q Oct 28 '16 at 13:05

1 Answers1

0

Please chceck if there is no error with

$pre->error_list;

or

$conn->error;

This should help to examine errors which occurred while parsing the SQL. Remember that prepare() method can return false when there is any error f.ex. syntax.

Karol Gasienica
  • 2,825
  • 24
  • 36