mysql_real_escape_string() expects parameter 1 to be string, array given |
Code: foreach($q->result_array() as $row) { If I attempt to fix the problem with the quotes inside the view instead I get this error: Message: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user....
Keep in mind the every element of the result_array() is an array itself. Usually it contains the fields you requested from your database.
I guess that one of your fields is named 'description'. If that is the case, modify the foreach loop like this: PHP Code: foreach($q->result_array() as $row) {
(04-23-2016, 12:56 AM)Wouter60 Wrote: Keep in mind the every element of the result_array() is an array itself. Usually it contains the fields you requested from your database. That's correct but it seems OP is looping through a query result. The mysql_real_escape_string() function is only for data being inserted into the database, so is not needed here. At least that's how I do it - otherwise I've been doing it wrong all this time!
mysql_real_escape_string — Escapes special characters in a string for use in an SQL statement.
If your using CI it escapes the query for you. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I ended up using a str_replace to get those quotes escaped before making a javascript array out of the data. Wasn't really using it to insert data going into a table... that's where the data is coming from.
@cupboy
1. You are trying to apply a function to a column in the returned array. What this function is going to do, what the goal is? 2. mysql_real_escape_string() is a function for escaping value when you prepare a SQL statement. You apply it on the returned result. Why? 3. mysql_real_escape_string() belongs to a certain SQL driver that is deprecated and as far as I know removed in PHP7. 4. mysql_real_escape_string() probably does not match to the current database driver that CodeIgniter uses. If you need such an escaping, see in documentation what routines the Database class provides. Remove this code, explain exactly what you intend to do.
|
Welcome Guest, Not a member yet? Register Sign In |