0
try {
mysql_query("INSERT xyz");
mysql_query("INSERT xyz");
mysql_query("INSERT xyz");
commit()
} catch (Exception $e) {
rollback()
}

I would like so that if any of the queries within the try { } fails, to go to the exception and rollback the transaction, and commit otherwise. What kind of things will it throw an exception for I.E if database is down? etc.

Another thing I've noticed is if something is rolledback, then a new record is made the primary key seems to have auto incremented twice, is this something that can be avoided somehow, or are tables which contains rows like (1, 2, 4, 7) for example bad to have as Primary Keys for any reason?

If someone could offer some advice on these issues it'd make me very happy :)

3
Contributors
6
Replies
9
Views
4 Years
Discussion Span
Last Post by LastMitch
0

asif49

I would like so that if any of the queries within the try { } fails, to go to the exception and rollback the transaction, and commit otherwise.

You are using Exceptions which is good! I guess you read it here:

http://php.net/manual/en/language.exceptions.php

Can you show the function that you are using because it's not very helpful by just using try{}?

0

I forgot to include some stuff. Here it is :)

function begin() {
mysql_query("BEGIN");
}

function commit() {
mysql_query("COMMIT");
}

function rollback() {
mysql_query("ROLLBACK");
}

.....

try {
begin()
mysql_query("INSERT xyz");
mysql_query("INSERT xyz");
mysql_query("INSERT xyz");
commit()
} catch (Exception $e) {
rollback()
}

What kind of things will be caught here as exceptions? Do I need to add any other error detection methods?

0

I haven't been able to find any good examples of how PDO works or what it is. Could you perhaps give an explanation?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.