3 4 5 MySQL Connection Test 6 7 20 21 22 23 24
25 26 30 32

MySQL connection test

33 34
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
Hostname(usually "localhost")
Username
Password
Database(optional)
63 64
65 66 67 68 Could not connect to the server '" . $hostname . "'

\n"; 80 echo mysql_error(); 81 }else{ 82 echo "

Successfully connected to the server '" . $hostname . "'

\n"; 83 // printf("MySQL client info: %s\n", mysql_get_client_info()); 84 // printf("MySQL host info: %s\n", mysql_get_host_info()); 85 // printf("MySQL server version: %s\n", mysql_get_server_info()); 86 // printf("MySQL protocol version: %s\n", mysql_get_proto_info()); 87 } 88 if ($link && !$database) { 89 echo "

No database name was given. Available databases:

\n"; 90 $db_list = mysql_list_dbs($link); 91 echo "
\n";  

92         while ($row = mysql_fetch_array($db_list)) {  

93             echo $row['Database'] . "\n";  

94         }  

95         echo "
\n"; 96 } 97 if ($database) { 98 $dbcheck = mysql_select_db("$database"); 99 if (!$dbcheck) { 100 echo mysql_error(); 101 }else{ 102 echo "

Successfully connected to the database '" . $database . "'

\n"; 103 // Check tables 104 $sql = "SHOW TABLES FROM `$database`"; 105 $result = mysql_query($sql); 106 if (mysql_num_rows($result) > 0) { 107 echo "

Available tables:

\n"; 108 echo "
\n";  

109                 while ($row = mysql_fetch_row($result)) {  

110                     echo "{$row[0]}\n";  

111                 }  

112                 echo "
\n"; 113 } else { 114 echo "

The database '" . $database . "' contains no tables.

\n"; 115 echo mysql_error(); 116 } 117 } 118 } 119 } 120 ?> 121 122
123 124