Re: DB memory grow with many select

From: Date: Fri, 15 Oct 2004 13:22:02 +0000
Subject: Re: DB memory grow with many select
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-14921@lists.php.net to get a copy of this message
* Vincent Sabourdy <v.sabourdy@s3g.fr>: > I have a problem with pear DB > > my code : > > for ($i=0;$i<100000;$i) Shouldn't that last bit be "$i++"? :-) > { > $sql = "select id from table where id=x"; Do you really mean 'id=x', or do you mean "id=$i"? > $db->query($sql); > } > > if i run this code memory usage grow up, during for loop > > but if i use mysql_query($sql) instead of $db->query($sql), > memory usage stay the same during all for loop > > Have you an idea to solve my problem ? Use DB's prepare() and execute() methods. prepare() will compile the SQL *on* the mysql server; compiled statements execute much faster. So, try this: $sql = "select id from table where id = ?"; $sth = $db->prepare($sql); for ($i = 0; $i < 100000; $i++) { $db->execute($sth, array($i)); } I think you'll find it performs much better. -- Matthew Weier O'Phinney | mailto:matthew@garden.org Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org

« previous php.pear.general (#14921) next »