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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么