|
Posted by burgermeister01@gmail.com on 08/28/07 20:57
On Aug 27, 2:57 pm, TechieGrl <cschal...@gmail.com> wrote:
> Prepared statements are new to me and having to do this with a multi-
> dimensional array is beyond me.
>
> Here is the prepared statement block:
>
> // Prepare to insert a record into table1
> $flag_insert = false;
> $sql_insert = "INSERT IGNORE INTO table1 ";
> $sql_insert .= "(ID, url)";
> $sql_insert .= "VALUES ";
> $sql_insert .= "($field1, $field2)";
> $stmt_insert = $db->stmt_init();
> if ($stmt_insert->prepare($sql_insert)){
> $flag_insert = true;
>
> }
>
> The array that I want to insert looks like this:
>
> Array (
> [0] => Array ( [0] => 1001 [1] =>www.google.com)
> [1] => Array ( [0] => 1002 [1] =>www.yahoo.com)
>
> Here is where I put the 2 together:
>
> // Insert the items into the database
> foreach ($rss->items_array as $i){
>
> if($flag_insert){
>
> $stmt_insert->bind_param($sql_insert, 'is', $field1, $field2);
> $field1 = $rss->items_array[$i][0];
> $field2 = $rss->items_array[$i][1];
> echo "sql " . $sql_insert . "\n";
> $stmt_insert->execute();
> } // if
> } // foreach ($ca as $location)
>
> Here is the error:
> Fatal error: Cannot pass parameter 2 by reference...
>
> Any thoughts would be so VERY much appreciated!!!
If I'm reading your code right, it should just be a simple matter of
correcting your array references.
I think the following lines of code need to change like so...
...
$field1 = $i[0];
$field2 = $i[1];
...
$i is already assigned to each subsequent value of $rss->items_array,
so in the code that you posted, you're iterating through the array and
then using one of the array's 2nd dimension arrays as an array
position. I haven't used the method you're employing to make sql
statements, so there could be further problems, but this one seems
fairly glaring to me.
[Back to original message]
|