开发者

Check with PHP whether a query will execute properly without any error

开发者 https://www.devze.com 2023-02-04 15:14 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消