On 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();

 "UNLOCK TABLES" is prolly trashing the result set;
 try swaping these two lines.


>     return $OrderID = $result[0];
>   } else {
>     return $OrderID;
>   }
> } // end func
> 

Regards,
-- 
Don Read                                       [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.
                            (53kr33t w0rdz: sql table query)

---------------------------------------------------------------------
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 <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to