Home >Backend Development >PHP Tutorial >The difference between mysql and mysqli in php_PHP tutorial
First of all, mysqli connection is a permanent connection, while mysql is a non-permanent connection.
Mysql connection will reopen a new process every time it is used for the second time, while mysqli only uses the same process, which can greatly reduce the pressure on the server side.
Secondly, mysqli encapsulates some advanced operations such as transactions, and also encapsulates many available methods in the DB operation process.
Mysqli transactions are widely used.
Example:
<span 1</span> <span $mysqli</span> = <span new</span> mysqli('localhost','root','','DB_Lib2Test'<span ); </span><span 2</span> <span $mysqli</span>->autocommit(<span false</span>);<span //</span><span 开始事务</span> <span 3</span> <span $mysqli</span>->query(<span $sql1</span><span ); </span><span 4</span> <span $mysqli</span>->query(<span $sql2</span><span ); </span><span 5</span> <span if</span>(!<span $mysqli</span>-><span errno){ </span><span 6</span> <span $mysqli</span>-><span commit(); </span><span 7</span> <span echo</span> 'ok'<span ; </span><span 8</span> }<span else</span><span { </span><span 9</span> <span echo</span> 'err'<span ; </span><span 10</span> <span $mysqli</span>-><span rollback(); </span><span 11</span> } <span //</span><span by www.jbxue.com</span>