multiple queries, one transaction
| From: | mayo | Date: | Tue, 17 May 2005 15:27:12 +0000 |
| Subject: | multiple queries, one transaction | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-39483@lists.php.net to get a copy of this message | ||
I would like to get the itemID number (autoincrement) of the last
insert.
(Insert order, get last orderID number and use it elsewhere.)
I'm having trouble understanding how to do a transaction in mysql/php
Code below:
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
('Error connecting to mysql');
$dbname = 'mail';
mysql_query("BEGIN"); // starts the transaction
mysql_query($query) or die('Error, insert query failed');
mysql_query($query2) or die('Error, select query failed');
$query = "INSERT INTO orders (orderDate) VALUES ('2005-05-17')";
$query = "SELECT max ordered FROM orders";
mysql_query($query) or die('Error, insert query failed');
mysql_query($query2) or die('Error, update query failed');
mysql_query("COMMIT"); // ends the transaction
mysql_close($conn);
?>
thx