|
Posted by Jerry Stuckle on 08/29/07 15:48
TechieGrl 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!!!
>
Amongst the array problem noted by burgermeister, your sql statement is
incorrect. You didn't leave any placeholders.
When using prepared statements with placeholders, you use "?" to
indicate where the parameters go. So your INSERT statement should look
something like:
INSERT IGNORE INTO table1 (ID, url) VALUES (?, ?)
Why this would cause the error you're seeing is beyond me, though.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|