Bananachipz
Bananachipz

Reputation: 13

php mysqli binding parameter:No data supplied for parameters in prepared statement

ok, this is my codes to bind the parameters dynamically.

$sql = "INSERT INTO `users` (`name`, `password`, `email`, `permission`) VALUES (?, ?, ?, ?)";
$sql_stmt =  $mysqli->prepare ($sql);

$test = array("ssss","1","2","3","4");

call_user_func_array(array($sql_stmt,'bind_param') ,$test);

$sql_stmt->execute();

I get a "No data supplied for parameters in prepared statement" error. However, the following line will work.

call_user_func_array(array($sql_stmt,'bind_param') ,array("ssss","1","2","3","4"));

I have no idea what is going on here.

edit I just tried doing a

echo $sql_stmt->param_count;

and I get a proper count of 4.

It will be of great help if I can be enlightened on this.

Thank you.

Upvotes: 1

Views: 2808

Answers (1)

Read the second note in PHP's page for bind_param. It says call_user_func_array() needs parameters to be passed by reference. So this should work:

$arr = array('ssss', '1', '2', '3', '4');
call_user_func_array( array($sql_stmt, 'bind_param'), &$arr );

Upvotes: 1

Related Questions