Test MySQL Connection

The following is a great way to verify a MySQL / MariaDB database connection issue. Create a file with with the name ultra-db-connect-test.php and populate it with the following information being sure to update the top four variables to your environment and run :


<?php
$dbname = 'name';
$dbuser = 'user';
$dbpass = 'pass';
$dbhost = 'host';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
  $tblCnt++;
  #echo $tbl[0]."<br ?---->\n";
}
if (!$tblCnt) {
  echo "No Tables Found<br />\n";
else {
  echo "There Are $tblCnt Tables<br />\n";
}




For additional information regarding PHP and modules on the server create a file with the name ultra-php-info.php and populate it with the following information :

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>




Sometimes you may need a different version of PHP, to switch PHP version log into your hosting control panel and click Select PHP Version.

If MySQL is giving you trouble, Ultra Web Hosting will be able to help you identify and resolve the issue. Click here to contact our support department.

 

  • 117 Users Found This Useful

Was this answer helpful?

Related Articles

How do I update my version of PHP?

PHP needs to be updated. What do I do?We make changing your version of PHP easy. Simply login to...

How do I change my PHP settings?

How do I change my PHP / PHP.INI settings?To change your PHP settings, just login to your hosting...

Learn About MariaDB

MariaDB is a fork of MySQL, which was created by Michael "Monty" Widenius. MySQL was acquired by...

What is the proper MariaDB - MySQL import and export format?

Sure, here are the steps on how to import and export databases using phpMyAdmin in your control...

Changing your PHP version

Have you received an error regarding your PHP version? If so, you may quickly and easily change...