Advertisement
Guest User

Untitled

a guest
Jan 31st, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. class Database
  3. {
  4.     private $host;
  5.     private $port;
  6.     private $dbname;
  7.     private $user;
  8.     private $password;
  9.     protected $conn;
  10.  
  11.     public function __construct($host, $port, $dbname, $user, $password) {
  12.         $this->host = $host;
  13.         $this->port = $port;
  14.         $this->dbname = $dbname;
  15.         $this->user = $user;
  16.         $this->password = $password;
  17.     }
  18.  
  19.     function error($error, $id)
  20.     {
  21.         // throw new Exception($error, $id);
  22.         echo $error.", ". $id;
  23.         die;
  24.        
  25.     }
  26.  
  27.     public function connect()
  28.     {
  29.         $result = $this->conn = pg_connect("host=$this->host port=$this->port dbname=$this->dbname user=$this->user password=$this->password");
  30.  
  31.         if (!$result) {
  32.             return $this->error("Blad polaczenia", 1);
  33.         } else {
  34.             echo '<span style="float:right;color:red;background-color:black;">Połączono z bazą danych.</span><br />';
  35.         }
  36.     }
  37. }
  38. ?>
  39.  
  40. ________________________________________________________________________________________________________________________________
  41.  
  42. <?php
  43.  
  44. require "db.php";
  45.  
  46. class Result extends Database
  47. {
  48.     private $save;
  49.     public function __construct() {
  50.         parent::__construct("127.0.0.1", 5432, "blue", "postgres", "postgres");
  51.     }
  52.  
  53.     public function validate($value = null, $secondData = null)
  54.     {
  55.  
  56.         $sql = 'INSERT INTO test(surname) VALUES(:symbol)';
  57.         $stmt = $this->conn->prepare($sql);
  58.         $stmt->bindValue(':symbol', "cos_tam");
  59.         $stmt->execute();
  60.         return "save";
  61.  
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement