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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥200 求能开发抖音自动回复卡片的软件
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。