Home >Backend Development >PHP Tutorial >The difference between mysql and mysqli in php_PHP tutorial

The difference between mysql and mysqli in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:14:06814browse


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>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440300.htmlTechArticleFirst of all, mysqli connection is a permanent connection, while mysql is a non-permanent connection. Whenever the mysql connection is used for the second time, a new process will be reopened, while mysqli only uses the same one...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn