Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. class DbConnection {
  2.  
  3.     private $connection;
  4.  
  5.     public function connect()
  6.     {
  7.           $this->connection = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
  8.           $this->connection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  9.     }
  10.  
  11.     public function query($query)
  12.     {
  13.         $result = $this->connection -> query($query);
  14.         while ($row = $result->fetch()) {
  15.             printf('<table><tr><td>%s</td><td>%s</td><td>%s</td></tr></table><br>',
  16.                 $row['id_ceginformacio'],
  17.                 $row['cegnev'],
  18.                 $row['vevokod']
  19.             );
  20.         }
  21.  
  22.         // ...
  23.     }
  24. }
  25.  
  26. $database = new DbConnection();
  27. $database->connect();
  28. $database->query("SELECT * FROM ".TBL_CEGINFORMACIO)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement