Re: [PHP] brain cramp, ouch!
Robert Cummings wrote: > > Kelly Meeks wrote: > > > > Ok > > > > Let's say I'm querying a table, and looping thru the results: > > > > $connect=mysql_connect(host,user,pass); > > $thedb=mysql_select(database1); > > $thequery="select * from foo"; > > $theresult=mysql_query($thequery) or die (mysql_error()) > > while ($output=mysql_fetch_assoc($theresult)){ > > > > do stuff here.. > > > > } > > > > What if while I'm looping, I want to take the information I'm looping thru, > > and want to write it to completely different database, assuming that the > > same username and password info works for both databases? > > > > Would you use multiple mysql_select_db statements, and then make refer. to > > the result of that select in your queries? > > > > I'm getting errors when I do that. > > > > Sorry to be so moronical, > > This is not moronical, it gets a lot of coders... what you need to do is > create another connection because the value returned from the mysql_connect > function is a resource identofier, which means if you run two queries on the > same connection the second result set will overwrite the first. Or maybe it's just the result set var that needs to be unique... I don't clearly remember since I have a pooling system that abstracts all this mess for me :) Cheers, Rob. -- .-. | Robert Cummings | :-`. | Webdeployer - Chief PHP and Java Programmer | :--: | Mail : mailto:[EMAIL PROTECTED] | | Phone : (613) 731-4046 x.109 | :--: | Website : http://www.webmotion.com | | Fax : (613) 260-9545 | `--' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] brain cramp, ouch!
Kelly Meeks wrote: > > Ok > > Let's say I'm querying a table, and looping thru the results: > > $connect=mysql_connect(host,user,pass); > $thedb=mysql_select(database1); > $thequery="select * from foo"; > $theresult=mysql_query($thequery) or die (mysql_error()) > while ($output=mysql_fetch_assoc($theresult)){ > > do stuff here.. > > } > > What if while I'm looping, I want to take the information I'm looping thru, > and want to write it to completely different database, assuming that the > same username and password info works for both databases? > > Would you use multiple mysql_select_db statements, and then make refer. to > the result of that select in your queries? > > I'm getting errors when I do that. > > Sorry to be so moronical, This is not moronical, it gets a lot of coders... what you need to do is create another connection because the value returned from the mysql_connect function is a resource identofier, which means if you run two queries on the same connection the second result set will overwrite the first. Cheers, Rob. -- .-. | Robert Cummings | :-`. | Webdeployer - Chief PHP and Java Programmer | :--: | Mail : mailto:[EMAIL PROTECTED] | | Phone : (613) 731-4046 x.109 | :--: | Website : http://www.webmotion.com | | Fax : (613) 260-9545 | `--' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] brain cramp, ouch!
On Fri, 17 May 2002, Kelly Meeks wrote: > Let's say I'm querying a table, and looping thru the results: > > $connect=mysql_connect(host,user,pass); > $thedb=mysql_select(database1); > $thequery="select * from foo"; > $theresult=mysql_query($thequery) or die (mysql_error()) > while ($output=mysql_fetch_assoc($theresult)){ >do stuff here.. > } > > What if while I'm looping, I want to take the information I'm looping > thru, and want to write it to completely different database, assuming > that the same username and password info works for both databases? > > Would you use multiple mysql_select_db statements, and then make refer. > to the result of that select in your queries? You don't need to switch back and forth unless you're actually sending queries to a particular database. Your result sets remain valid. Just make sure you don't overwrite them by using the same variables! mysql_select_db($db1); $result1 = mysql_query($query1); .. .. .. mysql_select_db($db2); $result2 = mysql_query($query2); // $result1 and $result2 are both valid here miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php