Guest User

Untitled

a guest
Dec 28th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <?php
  2.  
  3. class db {
  4.  
  5. var $host;
  6. var $db_name;
  7. var $username;
  8. var $password;
  9. var $res;
  10. var $query;
  11.  
  12. function __construct($host,$db_name,$username,$password){
  13. $this->host =$host;
  14. $this->password = $password;
  15. $this->username = $username;
  16. $this->db_name = $db_name;
  17. }
  18.  
  19.  
  20. function connect(){
  21. $this->res = mysqli_connect($this->host,$this->username,$this->password, $this->db_name);
  22. if(!$this->res)
  23. die($this->debug("connect"));
  24. }
  25.  
  26. function rowcount($query){
  27. $this->query = $query;
  28. $result = mysqli_query($this->res,$query) or die($this->debug("query"));
  29. return mysqli_num_rows($result);
  30. }
  31.  
  32. function debug($type) {
  33. switch ($type) {
  34. case "connect":
  35. $message = "MySQL Error Occured";
  36. $result = mysqli_errno() . ": " . mysql_error();
  37. $output = "Could not connect to the database. Be sure to check that your database connection settings are correct and that the MySQL server in running.";
  38. break;
  39.  
  40. case "database":
  41.  
  42. $message = "MySQL Error Occurred";
  43. $result = mysqli_errno($this->res) . ": " . mysqli_error($this->res);
  44. $output = "Sorry an error has occured accessing the database. Be sure to check that your database connection settings are correct and that the MySQL server in running.";
  45.  
  46. case "query":
  47.  
  48. $message = "MySQL Error Occurred";
  49. $result = mysqli_errno($this->res) . ": " . mysqli_error($this->res);
  50. $query = $this->query;
  51. }
  52.  
  53.  
  54. return $result.$query;
  55. }
  56.  
  57.  
  58.  
  59. function Q($type, $query){
  60. $this->query = $query;
  61. if($type=="select"){
  62. $result = mysqli_query($this->res, $query) or die($this->debug("query"));
  63. if(mysqli_num_rows($result) > 0){
  64. while($record = mysqli_fetch_array($result)){
  65. $data[] = $record;
  66. }
  67. return $data;
  68. }else{
  69. return false;
  70. }
  71. }else if($type=="insert") {
  72. $result = mysqli_query($this->res,$query) or die($this->debug("query"));
  73. return mysqli_insert_id($this->res);
  74. }else if($type=="update"){
  75. $result = mysqli_query($this->res,$query) or die($this->debug("query"));
  76. return $result;
  77. }else if($type == "delete"){
  78. $result = mysqli_query($this->res,$query) or die($this->debug("query"));
  79. return $result;
  80. }
  81. return false;
  82. }
  83. }
  84.  
  85. ?>
Add Comment
Please, Sign In to add comment