You can test connectivity to a MySQL database using the below script -
Sample Script
<?php
$dbname = ‘mysql_dbname’;
if (!mysql_connect(‘mysql_host’, ‘mysql_user’, ‘mysql_password’)) { echo ‘Could not connect to mysql’; exit; }
$sql = “SHOW TABLES FROM $dbname”;
$result = mysql_query($sql);
if (!$result) { echo “DB Error, could not list tablesn”; echo ‘MySQL Error: ‘ . mysql_error(); exit; }
while ($row = mysql_fetch_row($result)) {
echo “Table: {$row[0]}n”;
}
mysql_free_result($result);
?>
The variables used in the script are –
This script, on a successful connection, will fetch and display the names of all the tables in the specified database.
Tags: Database Connectivity, Database Name, Lt, Php, Php Mysql, Query Sql, Script Php, Successful Connection, Variables