ystanev

Untitled

Feb 16th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. // database configuration
  2. $DB["username"] = "root";
  3. $DB["password"] = "mysql";
  4. $DB["host"] = "localhost";
  5. $DB["dbname"] = "crud";
  6.  
  7. // make the database connection
  8. try {
  9.     $conn = new PDO("mysql:host=" . $DB["host"] .";".
  10.         "dbname=" . $DB["dbname"],
  11.         $DB["username"],
  12.         $DB["password"]);
  13.  
  14.     //echo "Connection Successful";
  15.  
  16.     // set the PDO error mode to exception
  17.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  18.  
  19.     // have my fetch data returned as an associative array
  20.     $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  21. }
  22. catch(PDOException $e)
  23. {
  24.     echo "Connection failed: " . $e->getMessage();
  25.     exit();
  26. }
Advertisement
Add Comment
Please, Sign In to add comment