Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

RE: [PHP-DB] multiple queries, one transaction
Thanks, the $orderId = mysql_insert_id($result) was what I was looking
for.

But in the long run, I'm still concerned about how to group several
queries into one transaction. As for example when one wants to make
multiple inserts with one submit.

Ex: User wants to input inventory. He's going to put in 11 new jeans
sizes 28-38

You create a loop inserting the following

itemType:jean
itemDesigner:Antik
itemSize:$i

This should all be one transaction. I would like to do this with
php/mysql.

Thx



-----Original Message-----
From: Jason [mailto:jasonc@lifepowersales.com]
Sent: Saturday, May 17, 2003 1:30 PM
To: 'mayo'
Subject: RE: [PHP-DB] multiple queries, one transaction

You could always use $orderId = mysql_insert_id($result) to pull the
autoinc
id that was created from your insert statement...

But I think your question revolves more around "how do I do a query"
then
"how do I pull the id back"
So to answer what I think your asking...
I write my queries like this:

$query  = "INSERT into orders(
orderData)
values(
'$orderData')";
$result = mysql_query($query);
$orderId= mysql_insert_id($result);

Hope that helps.

-----Original Message-----
From: mayo [mailto:mayo@nycinteractive.com]
Sent: Tuesday, May 17, 2005 8:27 AM
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


Report this thread to moderator Post Follow-up to this message
Old Post
Mayo
05-18-05 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP DB archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:06 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.