Advertisement
Guest User

class connection

a guest
Jan 31st, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. class connection {
  4.  
  5. /*** mysql hostname ***/
  6. protected $hostname = 'localhost';
  7. /*** mysql username ***/
  8. protected $username = 'root';
  9. /*** mysql password ***/
  10. protected $password = '';
  11. public $dbc;
  12.  
  13. public function __construct(){
  14.   try {
  15.   $this->dbc = new PDO("mysql:host={$this->hostname};dbname=test", $this->username, $this->password);
  16.     /*** echo a message saying we have connected ***/
  17.     echo"تم الإتصال بنجاح .";
  18.     }
  19. catch(PDOException $e)
  20.     {
  21.     echo $e->getMessage();
  22.     }
  23. }
  24.  
  25. public function insert($table,$rows,$values){
  26.   try {
  27.        return $this->dbc->exec("INSERT INTO ".$table."(".$rows.") VALUES ('".$values."')");
  28.       }
  29.   catch(PDOException $ie)
  30.   {
  31.     echo $ie->getMessage();
  32.   }
  33.   }
  34.  
  35. }
  36. $connection = new connection();
  37. $connection->insert("tbl", "name", "'star'");
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement