简体   繁体   English

PHP mysqli prepare语句bind_param布尔错误

[英]PHP mysqli prepare statement bind_param boolean error

Testing the statement from all side, but failed to find a solution for it. 从各个方面测试该语句,但未能找到解决方案。

// Insert the new user into the database 
 if( $insert_stmt = $mysqli->prepare("INSERT INTO client (username, email, 
 password, reg_ip, salt, country, ref_id, pin, ref_by, ref_by_2) VALUES ( ?, 
  ?, ?, ?, ?, ?, ?, ?, ?, ?)")){
     $insert_stmt->bind_param("ssssssssii", $username, $email, $pass_2, 
     $reg_ip, $random_salt, $countryname, $ref_code, $hashed_pin, $user_id3, 
     $user_id4);
     $insert_stmt->execute();

This never executes or gets inside the if statement. 这永远不会执行或进入if语句中。

I debugged it by removing the if part, that shows bind_param() is boolean error. 我通过删除if部分来调试它,该部分显示bind_param()是布尔错误。

 $insert_stmt = $mysqli->prepare("INSERT INTO client (username, email, 
 password, reg_ip, salt, country, ref_id, pin, ref_by, ref_by_2) VALUES ( ?, 
  ?, ?, ?, ?, ?, ?, ?, ?, ?)");
 $insert_stmt->bind_param("ssssssssii", $username, $email, $pass_2, $reg_ip, 
 $random_salt, $countryname, $ref_code, $hashed_pin, $user_id3, $user_id4);
 if($insert_stmt->execute()){

Fatal error: Call to a member function bind_param() on boolean 致命错误:在布尔值上调用成员函数bind_param()

I have done following test: 我已经完成以下测试:

  • All 10 variables data type test = OK (with gettype() function) 所有10个变量的数据类型均为test = OK(使用gettype()函数)
  • Variables data value = OK (printed all data value for checking) 变量数据值= OK(打印所有数据值以进行检查)
  • Mysql query statement = OK (tested on MYSQL directly with inputted data, mysql is inserting values) Mysql查询语句= OK(直接在MYSQL上使用输入的数据进行测试,mysql正在插入值)
  • There is no syntax error either. 也没有语法错误。
  • Variable alignment is = Ok 变量对齐=好
  • Data connection is = ok (as it runs other prepare statements without errors on same page) 数据连接=正常(因为它在同一页上运行其他prepare语句时没有错误)

Then where is the mistake? 那错误在哪里呢?

I figure it out. 我知道了。

Solution: It was not working because of the previous prepare statement $stmt_aff connection was not closed. 解决方案:由于先前的prepare语句$stmt_aff连接未关闭,因此无法正常工作。 Once I closed it. 一旦我关闭它。 Next Prepare statement $insert_stmt started working. 下一步Prepare语句$insert_stmt开始工作。

A good lesson learned why bind_param boolean error get produced if there are multiple prepare statement on the same page. 一个很好的经验教训是,如果同一页面上有多个prepare语句 ,为什么会产生bind_param布尔错误。

$stmt_aff->close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM