Advertisement
haikelfazzani

How To Connect To Database

Jul 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.36 KB | None | 0 0
  1. <?php
  2.     try{
  3.         $conn = "mysql:host=localhost;dbname=users_dbb";
  4.        
  5.         $connect = new PDO($conn,"root","");
  6.        
  7.         // set the PDO error mode to exception
  8.         $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  9.        
  10.         echo "you are connected successfully";
  11.        
  12.     }catch(PDOException $e){
  13.        
  14.         echo "Connection failed: " . $e->getMessage();
  15.        
  16.     }
  17. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement