MySQL Forums
Forum List  »  PHP

Re: Warning: mysqli_stmt::bind_param() [function.bind-param]: Number of variables doesn't match number of parameters in prepared statement in...
Posted by: Bas van Gaalen
Date: April 02, 2006 05:39AM

Here is a more precise case of what goes wrong:

----------------

$oMysql = new mysqli('localhost', '...', '...', '...');

$id_1 = 1;
$stmt = $oMysql->stmt_init();
$stmt->prepare("SELECT id FROM my_table1 WHERE id_1=?");
$stmt->bind_param("i", $id_1);
$stmt->execute();
$stmt->bind_result($id);

while ($stmt->fetch()) {
$stmt2 = $oMysql->stmt_init();
$stmt2->prepare("SELECT * FROM my_table2 WHERE id=?");
$stmt2->bind_param("i", $id); // this line will fail
$stmt2->execute();
$stmt2->store_result();
printf("%d rows selected.<br>", $stmt2->num_rows);
$stmt2->close();
}

----------------

The $stmt2->bind_param("i", $id); in the while loop will fail with this message:

Warning: mysqli_stmt::bind_param() [function.bind-param]: Number of variables doesn't match number of parameters in prepared statement in...

So even though the example I posted in my previous message works, this one does NOT! What is wrong with this code?

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.