Test SQL connection

From Servage Wiki
Revision as of 11:22, 2 July 2009 by Per (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

You can easily test a SQL connection using a simple PHP script to rule out any application error. This is done using a few lines of code.

Replace hostname (usually something like mysql1078.servage.net), username and password with the details you have for your database. There’s no need to add the database name.

Simple script to test SQL connection
  1. Check your controlpanel to ensure that the database is present and you have the user/pass to access database.
  2. Create an file with the online-file manager named mysqlcheck.php
  3. Edit this file by adding the below content:
 <?php
 $link = mysql_connect('mysqlXXXX.servage.net','dbuser','dbpassword');
 if (!$link) { die('Could not connect to MySQL: ' . mysql_error());
 } echo 'Connection OK'; mysql_close($link);
 ?>
  1. Execute yourdomain.com/mysqlcheck.php in your browser
Analyze the result
  • If a connection is made you will see ‘Connection OK’ and the fault is in the application/script.
  • If a connection can't be made, then you’ll probably see something like:

Warning: mysql_connect(): Access denied for user ‘dbuser’@'localhost’ in /yourdomain.com/mysqltest.php on line 2 or Could not connect to MySQL: Access denied for user ‘dbuser’@'host’

Copy and paste this error in a ticket to our customer support and we may be able to help you.

IMPORTANT: Remove script when problem is fixed.

Personal tools
Navigation