Advertisement
Guest User

db.php

a guest
Jan 28th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. <?php
  2.  
  3. $databaseHost = "localhost";
  4. $databaseName = "hackathon";
  5. $databaseUsername = "root";
  6. $databasePassword = "";
  7.  
  8. try {
  9.     // http://php.net/manual/en/pdo.connections.php
  10.     $dbConn = new PDO("mysql:host={$databaseHost};dbname={$databaseName}", $databaseUsername, $databasePassword);
  11.  
  12.     $dbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Setting Error Mode as Exception
  13.     // More on setAttribute: http://php.net/manual/en/pdo.setattribute.php
  14. } catch(PDOException $e) {
  15.     echo $e->getMessage();
  16. }
  17.  
  18. if ($dbConn){
  19.    echo 'connection to database is done successfully';
  20. }
  21.  
  22. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement