Mysql transaction using PDO

Executes an array of SQLs as a single transaction using PDO. Read more.

fork add to bundle source
function mysql_transaction($sqls) { $pdo = new PDO('mysql:host=;dbname=db', 'user', 'pwd'); $pdo->beginTransaction(); foreach ( $sqls as $sql ) { $pdo->exec($sql); if ( $pdo->errorInfo()[1] ) { $pdo->rollback(); return false; } } $pdo->commit(); return true; }


load_function('mysql_transaction'); mysql_transaction([ "INSERT INTO users SET email = ''", "INSERT INTO users_properties SET email = ''", "..." ]); // Will execute each query within a single transaction and return "true" on success
← how to use this in app?
create log ...inout