Guest User

Untitled

a guest
Feb 28th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php
  2. /**
  3. * DB manager Class
  4. */
  5. class db{
  6. /**
  7. * Define static variable
  8. */
  9. private static $host = "127.0.0.1:3306";
  10. private static $username = "root";
  11. private static $password ="";
  12. private static $database = "menu_designer";
  13. private static $coding ="utf8";
  14. private static $instance =null;
  15. private $connection ="";
  16. /**
  17. * Constructor
  18. */
  19.  
  20. public function __construct(){
  21. $this->connection =mysqli_connect(self::$host,self::$username,self::$password);
  22. if(mysqli_connect_errno($this->connection))
  23. {
  24. die("Could not connect mysqli database");
  25.  
  26. }
  27. else
  28. {
  29. mysqli_select_db($this->connection,self::$database);
  30. mysqli_set_charset($this->connection,self::$coding);
  31.  
  32. }
  33. }
  34. /** Singleton -> egyszerre csak egy példány létezhet! */
  35. public static function get(){
  36. if(is_null(self::$instance))
  37. {
  38. self::$instance= new db;
  39. }
  40. return self::$instance;
  41. }
  42. public function query($queryString){
  43. $result = mysqli_query($this->connection,$queryString);
  44. if(!$result){
  45. $this->error(mysqli_error ($this->connection),$queryString);
  46. }
  47. return $result;
  48. }
  49. public function insert_id(){
  50. return msqli_insert_id($this->connection);
  51.  
  52. }
  53. /** Elérhető sorok száma */
  54. public function numrows($queryString){
  55. $result= $this->query($queryString);
  56. return mysqli_num_rows($result);
  57. }
  58. public function getRow($queryString){
  59. $result = $this->query($queryString);
  60. return mysqli_fetch_assoc($result);
  61. }
  62. public function getArray($queryString){
  63. $rows = array();
  64. $result=$this->query($queryString);
  65. while($row = mysqli_fetch_assoc($result))
  66. {
  67. $rows[]=$row;
  68. }
  69. return $rows;
  70. }
  71. public function error($error,$squery){
  72. die("SQL err".$error."<br> with the following query: ".$squery);
  73. }
  74. public function escape($string){
  75. return mysqli_real_escape_string($this->connection, $string);
  76. }
  77.  
  78. }
Add Comment
Please, Sign In to add comment