Advertisement
QuantumA

PDO MySQL Connection Script

Oct 27th, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. **********************
  2.  
  3. BY QUANTUMA, FEEL FREE TO USE THIS AS YOU LIKE OF-COURSE ;)
  4.  
  5. **********************
  6.  
  7. <?php
  8.     include("connection.php"); #If you're using this, be sure to make a connection.php and define your mysql connection details.
  9.    
  10.     /* ======== GLOBAL SETTINGS ======== */
  11.     global $dbHost;     global $dbUsername;   global $dbPassword;   global $dbName;
  12.     global $dbOptions;  global $dbTableBans;  global $dbTableData;  global $db;
  13.     global $websiteContactEmail;
  14.     /* ======== GLOBAL SETTINGS ======== */
  15.    
  16.     try {
  17.         $db = new PDO("mysql:host={$dbHost};dbname={$dbName};charset=utf8", $dbUsername, $dbPassword, $dbOptions);
  18.     } catch(PDOException $ex) {
  19.         die("Database is currently offline, please contact the admistrator at " . $websiteContactEmail);
  20.     }
  21.    
  22.     $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  23.     $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  24.    
  25.     if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
  26.         function undo_magic_quotes_gpc(&$array) {
  27.             foreach($array as &$value) {
  28.                 if(is_array($value)) {
  29.                     undo_magic_quotes_gpc($value);
  30.                 } else {
  31.                     $value = stripcslashes($value);
  32.                 }
  33.             }
  34.         }
  35.        
  36.         undo_magic_quotes_gpc($_POST);
  37.         undo_magic_quotes_gpc($_GET);
  38.         undo_magic_quotes_gpc($_COOKIES);
  39.     }
  40.    
  41.     header("Content-Type: text/html; charset=utf8");
  42.     session_start();
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement