dqp4933 2017-03-15 18:57
浏览 78
已采纳

mysqli bind param问题:在布尔值上调用成员函数bind_param()

I want to update a table but i keep getting the error: Call to a member function bind_param() on boolean

What am i doing wrong? In my db setting looks like this:

  '{"name":"Product Slider","product_name":"","product":["240","375","5555"],"limit":"5","width":"600","height":"400","loop":"1","auto":"1","pager":"1","pause":"3000","speed":"800","status":"1"}'

My attempt to update:

 $sliderSql=$con->prepare("UPDATE oc_module SET setting = '{'name':'Product Slider','product_name':'','product':[?],'limit':'5','width':'600','height':'400','loop':'1','auto':'1','pager':'1','pause':'3000','speed':'800','status':'1'}' WHERE oc_module.module_id = 95");

$param="'".$calcSlider[0]."','".$laptopSlider[0]."','".$serverSlider[0]."'";

$sliderSql->bind_param("s",$param);
  • 写回答

1条回答 默认 最新

  • dpno17028 2017-03-15 19:13
    关注

    The quotes in your SQL are wrong. The single quotes in your JSON are terminating the string. Quotes in JSON have to be double quotes. Since they're embedded inside a string literal, you need to escape them.

    $sliderSql=$con->prepare("UPDATE oc_module SET setting = '{\"name\":\"Product Slider\",\"product_name\":\"\",\"product\":[?],\"limit\":\"5\",\"width\":\"600\",\"height\":\"400\",\"loop\":\"1\",\"auto\":\"1\",\"pager\":\"1\",\"pause\":\"3000\",\"speed\":\"800\",\"status\":\"1\"}' WHERE oc_module.module_id = 95");
    

    But there's another problem. You can't put a ? parameter inside a string literal -- they can only be used where a value expression is allowed.

    It would be easier if you used a separate variable, which you converted to JSON using json_encode().

    $setting = json_encode(array(
         "name" => "Product Slider",
         "product_name" => "",
         "product" => array($calcSlider[0], $laptopSlider[0], $serverSlider[0]),
         "limit" => "5",
         "width" => "600",
         "height" => "400",
         "loop" => "1",
         "auto" => "1",
         "pager" => "1",
         "pause" => "3000",
         "speed" => "800",
         "status" => "1"));
    $sliderSql = $con->prepare("UPDATE oc_module SET setting = ?");
    $sliderSql->bind_param("s", $setting);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?