Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2.  
  3. ConnectDB();
  4. // NOTE: this file has a password, and so should not be world-readable.
  5. // Usually it would be mode 600, with a ACL permitting the webserver in.  
  6. // But it's like this because you have to use it as sample code.
  7.  
  8. // ConnectDB() - takes no arguments, returns database handle
  9. // USAGE: $dbh = ConnectDB();
  10. function ConnectDB() {
  11.  
  12.    /*** mysql server info ***/
  13.     $hostname = '127.0.0.1';
  14.     $username = 'yourloginname';
  15.     $password = 'yourpassword';
  16.     $dbname   = 'yourloginname';
  17.  
  18.    try {
  19.        $dbh = new PDO("mysql:host=$hostname;dbname=$dbname",
  20.                       $username, $password);
  21. /*
  22.  * If you are on Elvis and using a MySQL5 account, you need this:
  23.  *
  24.  *  $dbh = new PDO("mysql:host=$hostname;port=3307;dbname=$dbname",
  25.  *                     $username, $password);
  26.  *
  27.  * because the mysql5 server listens on port 3307, not the default.
  28.  */
  29.  
  30.     }
  31.     catch(PDOException $e) {
  32.         die ('PDO error in "ConnectDB()": ' . $e->getMessage() );
  33.     }
  34.  
  35.     return $dbh;
  36. }
  37.  
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement