RE: PHP/MySQL Problem

From: Date: Tue, 30 Oct 2001 21:17:59 +0000
Subject: RE: PHP/MySQL Problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-72925@lists.php.net to get a copy of this message
Ahha. The error I was seeing was the next line of code, not the mysql_insert_id(). Thanks. That works now. -----Original Message----- From: rc [mailto:rebecca@digitalpulp.com] Sent: Tuesday, October 30, 2001 1:58 PM To: Matthew Walker Cc: mysql@lists.mysql.com Subject: Re: PHP/MySQL Problem Mysql_Insert_ID($dbhandle->connection); gets the last id of the last insert statement - if you do any db activity after the insert, this won't work. On Tue, 30 Oct 2001, Matthew Walker wrote: > 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 > > > > --- > > > -- > 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-thread89463@lists.mysql.com> > To unsubscribe, e-mail <mysql-unsubscribe-rebecca=digitalpulp.com@lists.mysql.com> > Trouble unsubscribing? Try: > http://lists.mysql.com/php/unsubscribe.php > --------------------------------------------------------------------- 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-thread89467@lists.mysql.com> To unsubscribe, e-mail <mysql-unsubscribe-matt=mountaintopherbs.com@lists.mysql.com> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php --- 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 (#72925) next »