Handy to write a small script to detect PHP connection to MySQL

Source: Internet
Author: User
Tags php and mysql php script

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.