Re: PHP/MySQL Problem...

From: Date: Tue, 30 Oct 2001 20:56:58 +0000
Subject: Re: PHP/MySQL Problem...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-72924@lists.php.net to get a copy of this message
Actually in the case of the last_insert_id() function the from and where statements are not used (check pg 547-548 of Paul's book). On Tuesday 30 October 2001 15:48, Frewuill Rodriguez wrote: > I don't such class but i think that > > $res = $dbhandle->query("select last_insert_id()"); > > is wrong in SQL syntax.. usually it a SELECT statement should look like > "SELECT fields from tables where clauses" > It seems you miss the table argument may you don't need query DB to get the > last id inserted but use a last_insert_id() function. > > Hope this helps. > > ----- Original Message ----- > From: "Matthew Walker" <matt@mountaintopherbs.com> > To: <php-general@lists.php.net> > Cc: <mysql@lists.mysql.com> > Sent: Tuesday, October 30, 2001 4:39 PM > Subject: [PHP] PHP/MySQL Problem... > > > Does anyone see anything wrong with the following code/query syntax? I'm > > using the PEAR DB class for PHP. When this runs, it correctly inserts > > the row to the table, but is failing to retrieve the last_insert_id(). > > > > function StartOrder() > > { > > global $dbhandle; > > global $OrderID; > > global $CustomerID; > > > > if (!($OrderID)) { > > $query = "INSERT INTO Orders (CustomerID) > > VALUES("; > > if ($CustomerID) { > > $query .= "\"" . $CustomerID . > > "\""; > > } else { > > $query .= "\"" . "\""; > > } > > $query .= ")"; > > $dbhandle->query("LOCK TABLES Orders WRITE"); > > $dbhandle->query($query); > > $res = $dbhandle->query("select > > last_insert_id()"); > > $dbhandle->query("UNLOCK TABLES"); > > $result = $res->fetchRow(); > > return $OrderID = $result[0]; > > } else { > > return $OrderID; > > } > > } // end func > > > > -- > > Matthew Walker > > Ecommerce Project Manager > > Mountain Top Herbs > > > > --- > > Outgoing mail is certified Virus Free. > > Checked by AVG anti-virus system (http://www.grisoft.com). > > Version: 6.0.286 / Virus Database: 152 - Release Date: 10/9/2001 > > --------------------------------------------------------------------- > Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <mysql-thread89462@lists.mysql.com> > To unsubscribe, e-mail > <mysql-unsubscribe-john=greengator.com@lists.mysql.com> Trouble > unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

« previous php.general (#72924) next »