$wpdb insert array

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 
    Array
(
[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);

Related posts

Leave a Reply

1 comment

  1. 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.