Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PEAR DB.php breaks on looping inserts?

Status
Not open for further replies.

thedaver

IS-IT--Management
Joined
Jul 12, 2001
Messages
2,741
Location
US
I run this code:

<?php
require_once('config/all.php');
$dbh=conn_db(&quot;database&quot;);
$diff=4;
$event=3;
for ($i=1;$i<=$diff;$i++) {
$sql=&quot;insert into phase values ('',$event,'no name',5)&quot;;
print &quot;$sql<br>\n&quot;;
$result=$dbh->getOne($sql);
}
?>

and get this output to screen (browser)
========================================================
insert into phase values ('',3,'no name',5)

Fatal error: Call to a member function on a non-object in /usr/local/lib/php/DB/common.php on line 831
========================================================

Am I doing something illegal by looping using &quot;getOne&quot; in this manner? All of my other DB.php queries are working fine!

ENV= PHP 4.3.4, , MySQL 3.23.57, Apache 1.3.29, Linux.





Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
Code:
&quot;insert into phase(fieldname1,fieldname2,fieldname3,fieldname4) values ('','$event','no name','5')&quot;;

I would do it like this

 
No change! STILL NEED HELP.

New code:
<?php
require_once('config/all.php');
$dbh=conn_db(&quot;spe&quot;);
$diff=4;
$event=3;
for ($i=1;$i<=$diff;$i++) {
$sql=&quot;insert into phase (ph_id,ph_ev_id,ph_name,ph_pos) values ('',$event,'no name',5)&quot;;
print &quot;$sql<br>\n&quot;;
$result=$dbh->getOne($sql);
$result->free();
}
?>


New Output:
==========================================================
insert into phase (ph_id,ph_ev_id,ph_name,ph_pos) values ('',3,'no name',5)

Fatal error: Call to a member function on a non-object in /usr/local/lib/php/DB/common.php on line 831
===========================================================

Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
Oh gawd am I stupid. You cannot getOne for an insert command.
A dunce cap and a star for me.

Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top