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.



Share this page:


Was this article useful? Have any suggestions or improvements to the information?

Also Read

How can I run PHP5?

PHP5 is now the default PHP ran on our servers. Nothing further is required.

Useful CSV to MySQL Script

Provided below is a great tool we have run into for converting CSV files into MySQL format: CSV...

What port is MariaDB - MySQL on?

MariaDB / MySQL is on Port 3306.      

What is the path to PHP5?

We are currently running the latest stable version of PHP5. /usr/bin/php

Changing Maximum Upload Size

Firts check your control panel for the "PHP Options" icon. If available you can change the PHP...