This 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.

 

<?php
$connect=mysql_connect('dbserver','dbuser','dbpassword') or die('Could not connect: ' . mysql_error());
mysql_select_db('dbname') or die('Could not open the db');
$showtablequery='SELECT * FROM `records` LIMIT 0 , 30';
echo 'Connected!';
$query_result=mysql_query($showtablequery);
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.

Found this article interesting?
Subscribe to DomainRegister´s newsletter!

You can unsubscribe at any time by simply clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp s privacy practices here.

  • MySQL, php
  • 2 uporabniku/om je bi članek v pomoč
Vam je bil odgovor v pomoč?

Povezani članki

 How To Insert a Carriage Return in a PHP String

If you need to insert a Carriage Return in a string in PHP: Carriage return is: "\r"  But...

 How to Create a phpinfo page

The phpinfo() function outputs a huge amount of information about the system you're using, such...

 How To Make a Redirect in PHP

If you want that a page redirects automatically the user to a certain page or site (let's say,...

 How To Configure Easy WP SMTP Plugin To Use Gmail SMTP Service

Easy WP SMTP is a popular and free plugin for WordPress to send email(s) by an authenticated SMTP...

 How to Backup Your MySQL Database Using PHP

This simple PHP script will provide a full dump of your MySQL database.You need to provide...