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!!! 4 2464
On Aug 27, 2:57 pm, TechieGrl <cschal...@gmail.comwrote:
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.
On Aug 28, 3:57 pm, "burgermeiste...@gmail.com"
<burgermeiste...@gmail.comwrote:
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.
Unfortunately, I made the changes as suggested and still get the same
error - Fatal error: Cannot pass parameter 2 by reference...
I replaced this:
$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();
With this:
$stmt_insert->bind_param($sql_insert, 'is', $field1, $field2);
$field1 = $i[0];
$field2 = $i[1];
echo "sql " . $sql_insert . "\n";
$stmt_insert->execute();
Thanks!
On Aug 28, 4:25 pm, TechieGrl <cschal...@gmail.comwrote:
On Aug 28, 3:57 pm, "burgermeiste...@gmail.com"
<burgermeiste...@gmail.comwrote:
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.
Unfortunately, I made the changes as suggested and still get the same
error - Fatal error: Cannot pass parameter 2 by reference...
I replaced this:
$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();
With this:
$stmt_insert->bind_param($sql_insert, 'is', $field1, $field2);
$field1 = $i[0];
$field2 = $i[1];
echo "sql " . $sql_insert . "\n";
$stmt_insert->execute();
Thanks!
Does it matter if you declare $field1 and $field2 before calling
bind_param(), e.g.
....
$field1 = $i[0];
$field2 = $i[1];
$stmt_insert->bind_param($sql_insert, 'is', $field1, $field2);
....
I'm not sure what database engine (mysql?pgsql?) or function
library(mysqli?3rd party?) you're using to do this. In fact, if this
suggestion doesn't help, that would be good information to post next
time.
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. js*******@attglobal.net
================== This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: yutlin |
last post by:
Hello,
Could anyone tell me if it is possible to bind a null value to a
statement? I.E.
$stmt->bind_param('isd',$var1,$var2,$var3);
$var1 = (something indicating null);
$var2 = (something...
|
by: Wonderinguy |
last post by:
Hi everybody , I have been trying to execute a simple DB2 stored
Procedure from perl. But it doesn't work. Could anybody please help me
find out why this is happening :
here is my perl script...
|
by: Samarth |
last post by:
Folks,
I am calling a DB2 stored procedure through Perl using the DBI:ODBC
module. I am not sure if I can do this or not because I have been able
to connect to and also issue select statements...
|
by: Uzytkownik |
last post by:
I've some function:
function show($id) {
$title = $text = $date = $nick = NULL;
$stmt = $this->base->stmt_init();
$stmt->prepare("SELECT title,text,datetime,nick FROM posts LEFT JOIN authors ON...
|
by: McHenry |
last post by:
I am trying to add a new row to a MySQL table using a stored procedure and
then obtain the new id value. The rows are added and affected _rows returns
1 confirming the statement worked however no...
| |
by: Dodger |
last post by:
Okay, background... yes, I am another of those evil, spurned, damnable
Perl mongers, but I'm not trying to start a flamewar, I'm juust tryung
to understand something...
I can write a script in...
|
by: toomanyjoes |
last post by:
I have written a function that runs a prepared statement and it seems
to run just fine but when I check to see the affected rows nothing is
affected. Can someone take a look at my code and tell me...
|
by: Ciaran Byrne |
last post by:
I'm trying to move data from one or more tables to identical table(s)
in a different database, likely on a different server. This prevents
me from using INSERT..SELECT, so up until now I've done a...
|
by: sugapablo |
last post by:
Here's my code:
<?php
$mysqli = new mysqli("localhost", "****", "********", "***********");
$idNum = "1030";
$sql = "select id,email from users where id ?;";
$stmt =...
|
by: clumsy_ninja |
last post by:
Why will the first snippet of code will not work with prepared
statements, while the second example works fine?
$table_name = 'my_table';
$query = 'SELECT * FROM ?';
if ($stmt->prepare($query))...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |