Re: PHP/MySQL Problem...

From: Date: Tue, 30 Oct 2001 20:48:10 +0000
Subject: Re: PHP/MySQL Problem...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-72922@lists.php.net to get a copy of this message
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 > >

« previous php.general (#72922) next »