mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
Update mysqli api support for transactions
* MySQL calls it autocommit mode: https://dev.mysql.com/doc/refman/8.0/en/innodb-autocommit-commit-rollback.html * Fix examples. Enable error reporting and remove closing tag * Fixed the two broken links and added mysqli::begin_transaction Patch contributed by Dharman <tekiela246@gmail.com>. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@351328 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
819cd5d7d1
commit
63319dea7d
1 changed files with 9 additions and 13 deletions
|
@ -1612,27 +1612,22 @@ to use near 'DROP TABLE mysql.user' at line 1
|
|||
<para>
|
||||
Transactions can either be controlled using SQL or API calls.
|
||||
It is recommended to use API calls for enabling and disabling the
|
||||
auto commit mode and for committing and rolling back transactions.
|
||||
<literal>autocommit</literal> mode and for committing and rolling back transactions.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Setting auto commit mode with SQL and through the API</title>
|
||||
<title>Setting <literal>autocommit</literal> mode with SQL and through the API</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno) {
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
}
|
||||
|
||||
/* Recommended: using API to control transactional settings */
|
||||
$mysqli->autocommit(false);
|
||||
|
||||
/* Won't be monitored and recognized by the replication and the load balancing plugin */
|
||||
if (!$mysqli->query('SET AUTOCOMMIT = 0')) {
|
||||
echo "Query failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
}
|
||||
?>
|
||||
$mysqli->query('SET AUTOCOMMIT = 0');
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -1642,7 +1637,7 @@ if (!$mysqli->query('SET AUTOCOMMIT = 0')) {
|
|||
can easily monitor API calls. The replication plugin offers transaction
|
||||
aware load balancing, if transactions are controlled with API calls.
|
||||
Transaction aware load balancing is not available if SQL statements are
|
||||
used for setting auto commit mode, committing or rolling back a transaction.
|
||||
used for setting <literal>autocommit</literal> mode, committing or rolling back a transaction.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
|
@ -1650,6 +1645,7 @@ if (!$mysqli->query('SET AUTOCOMMIT = 0')) {
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
$mysqli->autocommit(false);
|
||||
|
||||
|
@ -1658,7 +1654,6 @@ $mysqli->rollback();
|
|||
|
||||
$mysqli->query("INSERT INTO test(id) VALUES (2)");
|
||||
$mysqli->commit();
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -1673,8 +1668,9 @@ $mysqli->commit();
|
|||
<para>
|
||||
<simplelist>
|
||||
<member><methodname>mysqli::autocommit</methodname></member>
|
||||
<member><methodname>mysqli_result::commit</methodname></member>
|
||||
<member><methodname>mysqli_result::rollback</methodname></member>
|
||||
<member><methodname>mysqli::begin_transaction</methodname></member>
|
||||
<member><methodname>mysqli::commit</methodname></member>
|
||||
<member><methodname>mysqli::rollback</methodname></member>
|
||||
</simplelist>
|
||||
</para>
|
||||
</section>
|
||||
|
|
Loading…
Reference in a new issue