Check with PHP whether a query will execute properly without any error
I want to check with PHP whether a query will execute properly without any error.
Say 开发者_JAVA百科I want to check if inserting a particular record into a table is valid without actually inserting it.
I use the deadly combo PHP + MySQL :)
Open new transaction and roll it back after test query execution. Use mysql_error() to check if test query was successful.
1: Open up a mysqli connection $conn
$conn->autocommit(false);
$conn->query("INSERT x into y");
echo $conn->error;
$conn->rollback();
$conn->close(); //Without committing changes
start your set of queries with the MySql statement "start transaction", then wrap you following statements in try/catch blocks and then either send a "commit" or a "rollback"
see here on transactions in mysql
精彩评论