Guest User

Untitled

a guest
Mar 15th, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class Database{
  5.  
  6.   private $host = "localhost";
  7.   private $db_name = "amg_db";
  8.   private $username = "root";
  9.   private $password = "";
  10.   public $conn;
  11.  
  12.   public function getConnection(){
  13.  
  14.     $this->conn = null;
  15.  
  16.     try {
  17.       $this->conn = new PDO("mysql:host=".$this->host.";dbname=".$this->db_name, $this->username, $this->password);
  18.     } catch (PDOException $exception) {
  19.       echo "Connection Error! ". $exception->getMessage();
  20.     }
  21.  
  22.     return $this->conn;
  23.   }
  24. }
  25.  
  26.  
  27. $database = new Database();
  28. $db = $database->getConnection();
  29.  
  30. $query = "CREATE TABLE test (
  31.    id INT(11)
  32. );";
  33.    
  34. $stmt = $db->prepare($query);
  35. $stmt->execute();
  36.  
  37. ?>
Add Comment
Please, Sign In to add comment