2016-07-13 06:05
浏览 75

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) {
  string(7) "GLY0YQ5"
  array(0) {
  string(15) "EPPING NSW 2121"
  string(17) "RICHMOND VIC 3121"
  string(6) "EPPING"
  string(4) "2121"
  string(3) "NSW"
  string(8) "RICHMOND"
  string(4) "3121"
  string(3) "VIC"
  string(10) "-33.772549"
  string(10) "151.082365"
  string(10) "-37.818587"
  string(10) "144.999181"
  string(1) "0"
  string(1) "0"
  string(1) "0"
  string(1) "0"
  string(1) "0"
  string(2) "39"
  string(3) "897"
  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
      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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题