For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > May 2005 > RE: [PHP-DB] multiple queries, one transaction









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [PHP-DB] multiple queries, one transaction
Miguel Guirao

2005-05-18, 3:57 am

There is a function that gets the last auto increment value for an ID
field!!

-----Original Message-----
From: mayo [mailto:mayo@nycinteractive.com]
Sent: Martes, 17 de Mayo de 2005 10:27 a.m.
To: php-db@lists.php.net
Subject: [PHP-DB] multiple queries, one transaction


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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com