Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. class database{
  2.  
  3. public $dbHost = '';
  4. public $dbUser = '';
  5. public $dbPass = '';
  6. public $dbName = '';
  7.  
  8. public $db;
  9.  
  10. public function __construct(){}
  11.  
  12. public function dbConnect(){
  13.     $mysqli = new mysqli($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName);
  14.  
  15.     /* check connection */
  16.     if (mysqli_connect_errno()){
  17.         printf("Connect failed: %s\n", mysqli_connect_error());
  18.         exit();
  19.     }else{
  20.         echo 'connection made';
  21.     }
  22.     /* close connection */
  23.     $mysqli->close();
  24. }
  25.  
  26. public function query($sql){
  27.     $query = $sql;
  28.     self::preparedStatement($query);
  29. }
  30.  
  31. public function preparedStatement(){
  32.     if ($stmt = $mysqli->prepare($query)){
  33.  
  34.         /* execute statement */
  35.         $stmt->execute();
  36.  
  37.         /* bind result variables */
  38.         $stmt->bind_result($name, $code);
  39.  
  40.         /* fetch values */
  41.         while ($stmt->fetch()) {
  42.             printf ("%s (%s)\n", $name, $code);
  43.         }
  44.  
  45.         /* close statement */
  46.         $stmt->close();
  47.     }
  48. }
  49.  
  50. public function __destruct(){}
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement