Discussion on the difference analysis between mysql and mysqli in php

  • 2020-06-12 08:43:15
  • OfStack

The first two functions are for DB.
First, mysqli connections are permanent, while mysql is non-permanent. What does that mean? mysql connections reopen a new process each time they are used the second time, while mysqli only USES the same process, which greatly reduces server-side stress.
Second, mysqli encapsulates advanced operations such as transactions, as well as many of the methods available during DB operations.
One place where mysqli is used more is for transactions.
Take the following example:

$mysqli = new mysqli('localhost','root','','DB_Lib2Test');
$mysqli->autocommit(false);// To start things 
$mysqli->query($sql1);
$mysqli->query($sql2);
if(!$mysqli->errno){
  $mysqli->commit();
  echo 'ok';
}else{
 echo 'err';
  $mysqli->rollback();
}
   


Related articles: