Advertisement
Guest User

Untitled

a guest
Jan 31st, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. class SQL {
  2.     protected $handler;  
  3.     protected $hostname = 'localhost';
  4.     protected $password = '';
  5.     protected $username = 'root';
  6.     protected $dbname   = 'test';
  7.  
  8.     public function __construct() {
  9.         try {
  10.             $this->handler = new PDO("mysql:host={$this->hostname};dbname={$this->dbname}", $this->username, $this->password);
  11.         }
  12.         catch(PDOException $e) {
  13.             echo $e->getMessage();
  14.         }
  15.     }
  16.    
  17.     public function insert($table,$rows,$values){
  18.        return $this->handler->exec("INSERT INTO ".$table."(".$rows.") VALUES ('".$values."')");
  19.     }
  20. }
  21.  
  22. $sql = new SQL();
  23. $sql->insert("users", "username,password", "'hisham', 'startimes'");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement