0

Is there a way to drop non primary key column from specific table using prepared statement?
I tried this

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

// prepare and bind
    $stmt = $conn->prepare("ALTER TABLE staff DROP COLUMN :col_name");
    $stmt->bind_param(":col_name", $column_name);

// set parameters and execute
    $column_name = "job_type1";
    $stmt->execute();

But get this error:

Call to a member function bind_param() on boolean

Mike
  • 23,542
  • 14
  • 76
  • 87
Calvin
  • 605
  • 10
  • 26

1 Answers1

0

As stated in the documentation:

mysqli_prepare() returns a statement object or FALSE if an error occurred.

Therefor, you should check if the returned value is FALSE before continuing.

This might be the cause of you error.

Furthermore, you can see what the actual error is by calling:

$mysqli->error

afterwards.

Arthur Feldman
  • 107
  • 4
  • 14