Al_Faqun

/includes/db.inc.php

Aug 21st, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. <?php
  2.    
  3.     if (!$config){
  4.         $error = 'No config! Please, specify config before using `db.inc.php`';
  5.         include $_SERVER['DOCUMENT_ROOT'] . '/error.html.php';
  6.         exit();
  7.     }
  8.    
  9.     $mysqli = new mysqli('localhost', $config['username'], $config['password']);
  10.     if ($mysqli->connect_errno) {
  11.         echo "Failed to connect to MySQL: " . $mysqli->connect_error;
  12.         exit();
  13.     }
  14.  
  15.     if (!$mysqli->set_charset('utf8'))
  16.     {
  17.         $output = 'Unable to set Database connection encoding';
  18.         include $_SERVER['DOCUMENT_ROOT'] .'/output.html.php';
  19.         exit();
  20.     }
  21.     if (!$mysqli->select_db($config['dbname']))
  22.     {
  23.         $error = 'Unable to locate database.';
  24.         include $_SERVER['DOCUMENT_ROOT'] . '/error.html.php';
  25.         exit();
  26.     }
  27.  ?>
Advertisement
Add Comment
Please, Sign In to add comment