Created
July 3, 2015 13:34
-
-
Save raulanatol/eab8a6148476c87d55fc to your computer and use it in GitHub Desktop.
Database check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $hostname = ""; | |
| $username = ""; | |
| $password = ""; | |
| $database = ""; | |
| $link = mysql_connect($hostname, $username, $password); | |
| if ( ! $link) { | |
| echo "<p>Could not connect to the server '" . $hostname . "'</p>\n"; | |
| echo mysql_error(); | |
| } else { | |
| echo "<p>Successfully connected to the server '" . $hostname . "'</p>\n"; | |
| } | |
| if ($link && ! $database) { | |
| echo "<p>No database name was given. Available databases:</p>\n"; | |
| $db_list = mysql_list_dbs($link); | |
| while ($row = mysql_fetch_array($db_list)) { | |
| echo $row['Database'] . "\n"; | |
| } | |
| } | |
| if ($database) { | |
| $dbCheck = mysql_select_db("$database"); | |
| if ( ! $dbCheck) { | |
| echo mysql_error(); | |
| } else { | |
| echo "<p>Successfully connected to the database '" . $database . "'</p>\n"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment