PHP Script to Test MySQL Database Connectivity*
Posted by Ryan D, Last modified by Madhusudan S on 05 August 2015 05:31:08 PM

Provided below is a simple PHP script to test MySQL database connectivity. The result of this script displays the names of the tables present within the specified database.

Sample Script

        $connect=mysql_connect("dbserver","dbuser","dbpassword") or die("Unable to Connect");
        mysql_select_db("dbname") or die("Could not open the db");
        $showtablequery="SHOW TABLES FROM dbname";
        while($showtablerow = mysql_fetch_array($query_result))
        echo $showtablerow[0]." ";

Explanation about the variables used in the script:

  • dbserver: Mention the value as localhost for Linux Hosting (cPanel). For Windows Hosting (Plesk), MySQL Server IP needs to be mentioned.



  • dbname: Specify complete database name including the prefix. For example, reseloaq_mysql.

  • dbuser: Mention the database user associated with the database.

  • dbpassword: Mention the password for the above database user.

(0 vote(s))
Not helpful

Comments (0)
Post a new comment
Full Name: