There are two PHP to MySQL Connection functions:
-
The Procedural function: mysql_connect
-
The Object Oriented function: mysqli_connect
Not Every Host Successfully Support a Version of PHP/MySQL that Permit you to use Both Methods…
So on a Remote Host you need to check which Versions of PHP and MySQL are Supported for to know after which methods of Connection you can Use.
-
Test MySQL Connection by mysql_connect function
Just Insert in your PHP Script
?>DEFINE('DB_USER','yourUserName');
DEFINE('DB_PASSWORD', 'yourMySQLPass');
DEFINE('DB_HOST', 'yourMySQLHost');
DEFINE('DB_NAME', 'yourMySQLDbName');
$dbc = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
/nif (!$dbc) {
die('Connect Error (' . mysql_errno() . ') ' . mysql_error());
$db_selected = mysql_select_db(DB_NAME);
/nif (!$db_selected) {
die ('Can't use' . DB_NAME . ': ' . mysql_error());
}
/necho 'Success... your connection to the Database is working';
}
?>
If you have some Error in Connection this will be directly displayed on the Page.
-
Test MySQL Connection by the mysqli_connect function
?>DEFINE('DB_USER','yourUserName');
DEFINE('DB_PASSWORD', 'yourMySQLPass');
DEFINE('DB_HOST', 'yourMySQLHost');
DEFINE('DB_NAME', 'yourMySQLDbName');
$link = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
/nif (!$link) {
die('Connect Error (' . mysqli_connect_errno() . ') ' mysqli_connect_error());
}
/necho 'Success... ' . mysqli_get_host_info($link) . "n";
mysqli_close($link);
?>
In case of Successful Connection you will see a message of Success…