doutouman6245 2016-07-13 06:05
浏览 96
已采纳

PHP警告:mysqli :: real_escape_string()期望参数1为字符串,给定数组

I'm getting a warning from PHP:

PHP Warning: mysqli::real_escape_string() expects parameter 1 to be string, array given in ..

The code giving the warning is:

$saveData = array_map(array($connection, 'real_escape_string'), $saveData);

$saveData is decoded JSON taken from $_POST - typical dataset would be:

array(22) {
  ["quoteID"]=>
  string(7) "GLY0YQ5"
  ["Inventory"]=>
  array(0) {
  }
  ["pickupLocation"]=>
  string(15) "EPPING NSW 2121"
  ["dropOffLocation"]=>
  string(17) "RICHMOND VIC 3121"
  ["pickupSuburb"]=>
  string(6) "EPPING"
  ["pickupPostcode"]=>
  string(4) "2121"
  ["pickupState"]=>
  string(3) "NSW"
  ["dropoffSuburb"]=>
  string(8) "RICHMOND"
  ["dropoffPostcode"]=>
  string(4) "3121"
  ["dropoffState"]=>
  string(3) "VIC"
  ["pickupLatitude"]=>
  string(10) "-33.772549"
  ["pickupLongitude"]=>
  string(10) "151.082365"
  ["dropoffLatitude"]=>
  string(10) "-37.818587"
  ["dropoffLongitude"]=>
  string(10) "144.999181"
  ["pickupDistance"]=>
  string(1) "0"
  ["pickupAccess"]=>
  string(1) "0"
  ["dropoffDistance"]=>
  string(1) "0"
  ["dropoffAccess"]=>
  string(1) "0"
  ["regionalLoading"]=>
  string(1) "0"
  ["totalVolume"]=>
  string(2) "39"
  ["totalDistance"]=>
  string(3) "897"
  ["totalPrice"]=>
  string(4) "3120"
}

My understanding is the issue is mysqli expecting the first parameter to be the $connection variable, which it actually is, it's just different to the regular mysqli format because of the format required by array_map.

Given the outcome desired is the real_escape the entire array in one shot, and that the error is just a warning and is actually working, is there a better way to do this, and is it even necessary to make an adjustment?

  • 写回答

1条回答 默认 最新

  • dsfdgdsfd23212 2016-07-13 06:30
    关注
    ["Inventory"]=>
      array(0) {
      }
    

    Your problem is that your data contains an array, which cannot be escaped by mysqli::real_escape_string and which is triggering the warning. Make sure all values in the array are scalar values, not complex values like arrays, before attempting to escape them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法