Recently accidentally touched a little bit of PHP development, to use the MySQL database, due to MySQL and PHP version of the relationship, PHP5 inside the connection function has mysql_connect (), Mysqli_connect () two, PHP7 and used mysqli () object, it may be necessary to debug these problems later on in some other projects, and write a small PHP script to detect the current connection status between PHP and MySQL and the connection functions that can be used, the code is as follows:
<?PHPHeader("Content-type:text/html;charset=utf-8");$server= "localhost";$username= "Root";$password= "123456";Echo' Start MySQL database connection. <br><br><br> ';$mysqli=NewMysqli ($server,$username,$password);if($mysqli){ Echo' Connect MySQL database successfully. <br> '; Echo' can use \ ' new mysqli () \ ' to Connect.<br><br> '; $mysqli-close ();}if($con 1=Mysqli_connect($server,$username,$password)){ Echo' Connect MySQL database successfully. <br> '; Echo' Can use Mysqli_connect () to Connect.<br><br> '; Mysqli_close($con 1);}if($con 2=mysql_connect($server,$username,$password)) { Echo' Connect MySQL database successfully. <br> '; Echo' Can use mysql_connect () to Connect.<br><br> '; Mysql_close($con 2);}Else{ die(' connection to MySQL database failed: '.Mysql_error());}Echo' <br><br><br> ';Echo' Close the MySQL database connection. ‘;?>
The database connection information followed by server information in $server, $username, replaced $password, and then access the script, you can get the current server, PHP support all MySQL connection functions.
Handy to write a small script to detect PHP connection to MySQL