darxysaq
darxysaq

Reputation: 761

Number of variables doesn't match number of parameters in prepared statements

$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '?'";
$stmt = $db->prepare($sql);
$stmt->bind_param("s", $database);
$stmt->execute();
$resultSet = $stmt->get_result();

It says "Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in..."

Can somebody explain what's wrong? $database is a string.

Upvotes: 2

Views: 430

Answers (1)

Shaeldon
Shaeldon

Reputation: 883

If you use ? as a placeholder, don't use ticks ' s

$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param('s', $database);
$stmt->execute();
$resultSet = $stmt->get_result();

Upvotes: 2

Related Questions