WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to insert multiple array. I get error: mysql_real_escape_string() expects parameter 1 to be string, array given

My example code:

 $array_info is 
[0] => Array
        [0] => a
        [1] => b
        [2] => c

[1] => Array
        [0] => d
        [1] => e
        [2] => f


 $data = array(
        'blog_id' => NULL,
        'post_id' => $id,
        'ing' => $array_info
        $insert = $wpdb->insert($table_name, $data);
share|improve this question
What is your $table_name value? – birgire Mar 25 '13 at 9:05
This value is correct wp_tablename – andys Mar 25 '13 at 11:41
Per the Codex page on WPDB, $wpdb->insert() expects $data to be an array of column => value pairs. Your $data array doesn't meet that criterion. – Pat J Mar 25 '13 at 13:48
You provided no context to your question, it's not clear why you are doing this, or what the purpose is, as such it is very hard to determine what a correct answer would actually be. Also we do not see the code that generates array_info – Tom J Nowell Mar 25 '13 at 16:26
Also, array_info is an array, not a string, as the error says – Tom J Nowell Mar 25 '13 at 16:27

What is your table structure. Please be aware that a $wpdb->insert call translate the array to an sql statement of the form

INSERT INTO table_name VALUES (value1, value2, value3,...)

Since there is no such thing as an array type for colums in sql, you will need to either serialize any subarray or make a seperate field for each item in the sub array (and move items from the subarray to the main array).

Please be aware that it is generally not a good practice to have structured data inside a SQL field.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.