Call to a member function real_escape_string() on array in

1k Views Asked by At

I am struggling with something strange. I am running a mysqli::real_escape_string on a function to prepare an SQL statement. I am taking data from one database and developing a query to insert it into a database on a different server.

There error message I get is:

Fatal error: Uncaught Error: Call to a member function real_escape_string() on array in ...

I tried logging a is_array() function right before calling the real_escape_string() and it confirms that it is not an array. I am getting this whether I pass in a numeric or a string value. I thought perhaps it was an encoding issue, but I'm not sure how to deal with those. I tried to convert it before, but that also didn't work:

$str = $row[$key];                     // Tried on two strings '1' (is_numeric = True), and 'Kevin'
is_array( $str );                      // Returns False
$str = mb_convert_encoding($row[$key], 'UTF-8');    // Consequently, also tried 'latin1' with the same result.
$db->real_escape_string( $str ); 

That also did not work, still is returning the array error.

Any other suggestions on what to try?

Thanks.

2

There are 2 best solutions below

0
Erkin  Pardayev On

Check your variable with function var_dump()

var_dump($str);
1
Your Common Sense On

This error means that it's your $db is array, not the function's parameter