Skip to content

Instantly share code, notes, and snippets.

@dkarandana
Last active December 18, 2018 07:13
Show Gist options
  • Save dkarandana/82dc6ac7052c5492517d4be1808bad62 to your computer and use it in GitHub Desktop.
Save dkarandana/82dc6ac7052c5492517d4be1808bad62 to your computer and use it in GitHub Desktop.
PHP MySQL Connection
<?php
defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
defined('DB_USER') ? null : define("DB_USER", "******");
defined('DB_PASS') ? null : define("DB_PASS", "******");
defined('DB_NAME') ? null : define("DB_NAME", "IMDBTop100");
$mysqli = mysqli_connect( DB_SERVER, DB_USER, DB_PASS, DB_NAME);
if ( !$mysqli ) {
$connection = "Error: Unable to connect to MySQL." . PHP_EOL;
$connection .= "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
$connection .= "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit( $connection );
}else{
$connection = "Connection success - Host information: " . mysqli_get_host_info( $mysqli );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment