Skip to content

Instantly share code, notes, and snippets.

@ron4stoppable
Created November 13, 2013 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ron4stoppable/7455344 to your computer and use it in GitHub Desktop.
Save ron4stoppable/7455344 to your computer and use it in GitHub Desktop.
<?php
$link = mysqli_connect('localhost', 'user', 'password'); //replace user with root of the user name
if (!$link)
{
$output = 'Unable to connect to the database server.'; // If connection to MySQL server fails
include 'output.html.php'; // error message will be stored $output
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
$output = 'Unable to set database connection encoding.';
include 'output.html.php';
exit();
}
if (!mysqli_select_db($link, 'some-table'))
{
$output = 'Unable to locate the some-table database.';
include 'output.html.php';
exit();
}
$output = 'Database connection established.';
include 'output.html.php';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment