Since these two inserts are executed independently, another program running concurrently might see the database in a state where the first insert is done but the second isn't Whether this is a problem or not depends on the application logic. In your case it's hard to tell without additional information. Probably not.
A financial transactions involving two accounts is an example where this is a problem: you don't want the sum of all account balances to be wrong at any time If you think you need this, you can make the operation atomic at the cost of performance: another program will either see the database before the first insert, or after the second insert. It works like this: $result = FALSE; if (mysql_query('BEGIN')) { if (mysql_query($query1) && mysql_query($query2)) $result = mysql_query('COMMIT'); // both queries looked OK, save else mysql_query('ROLLBACK'); // problems with queries, no changes } The storage engine has to support transactions, i.e. , it has to be InnoDB Otherwise this will silently not work.
Since these two inserts are executed independently, another program running concurrently might see the database in a state where the first insert is done but the second isn't. Whether this is a problem or not depends on the application logic. In your case it's hard to tell without additional information.
Probably not. A financial transactions involving two accounts is an example where this is a problem: you don't want the sum of all account balances to be wrong at any time. If you think you need this, you can make the operation atomic at the cost of performance: another program will either see the database before the first insert, or after the second insert.It works like this: $result = FALSE; if (mysql_query('BEGIN')) { if (mysql_query($query1) && mysql_query($query2)) $result = mysql_query('COMMIT'); // both queries looked OK, save else mysql_query('ROLLBACK'); // problems with queries, no changes } The storage engine has to support transactions, i.e.
, it has to be InnoDB. Otherwise this will silently not work.
SQL inserts are for a single table only. You can't insert data into two or more tables at the same time with a single INSERT query. You can force the separate insertions to be atomic by using a transaction, but you still have to do an INSERT for each table.
Might be nice if you could so something like INSERT INTO t1. Id, t2. Val, t3.
Other VALUES ($t1id, $t2val, $t3other); but alas...
Mysql_insert_id() will just use the most recent connection if there is no explicit $link being used. So the above example in the manual page itself should behave the same with mysql_insert_id($link) at the end instead of the mysql_insert_id() they used. If you had multiple connections, the $link might come in handy.
Also in reading the mysql manual itself, there is some enlightening information on the fact that this does appear to be totally safe to use because it is on a per-connection basis. "The last ID that was generated is maintained in the server on a per-connection basis.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.