0

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
  • 1
    i trust php if it says its an array, it is Commented Nov 18, 2017 at 6:13
  • What is in $db? Commented Nov 18, 2017 at 6:32

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, so obvious, I should have thought of that! You were right, that was the problem. I was so focused on $str I didn't think to look at $db. Thanks for your help!
-1

Check your variable with function var_dump()

var_dump($str);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.