database.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. class Database
  3. {
  4. function __construct()
  5. {
  6. $this->customer_table = "customer";
  7. $this->category_table = "category";
  8. $this->product_table = "product";
  9. $this->price_table = "price";
  10. $this->priceset_table = "priceset";
  11. $this->tax_table = "tax";
  12. $this->bill_table = "bill";
  13. $this->bill_product_table = "bill_product";
  14. $this->tour_table = "tour";
  15. $this->assistant_table = "assistant";
  16. $this->group_table = "`group`";
  17. $this->customer_template_table = "customer_template";
  18. $this->ready = false;
  19. }
  20. function connectToDb()
  21. {
  22. $host = "mysql5.nebulon.de";
  23. $user = "db30675_9";
  24. $password = "manda1337";
  25. $db = "db30675_9";
  26. // $host = "localhost";
  27. // $user = "root";
  28. // $password = "";
  29. // $db = "faursprung_net";
  30. $this->db_link = mysqli_connect($host, $user, $password);
  31. if(!$this->db_link)
  32. exit("Error: ".mysqli_connect_error());
  33. if(!mysqli_select_db($this->db_link, $db))
  34. exit("Error: selecting db");
  35. $this->ready = TRUE;
  36. }
  37. function query($query)
  38. {
  39. if(!$this->ready)
  40. $this->connectToDb();
  41. if(!($result = mysqli_query($this->db_link, $query)))
  42. echo "Error: ".mysqli_error($this->db_link);
  43. return $result;
  44. }
  45. function fetchRows($result)
  46. {
  47. if(!$this->ready)
  48. $this->connectToDb();
  49. $all_rows = array();
  50. while($row = mysqli_fetch_row($result))
  51. $all_rows[] = $row;
  52. return $all_rows;
  53. }
  54. function writeToFile($path, $data)
  55. {
  56. $file_access_ok = true;
  57. $file_open = false;
  58. clearstatcache();
  59. if (file_exists($path))
  60. if (!is_writable($path))
  61. $file_access_ok = false;
  62. if ($file_access_ok and (!$file_handle = fopen($path, "w+b")))
  63. $file_access_ok = false;
  64. if ($file_access_ok)
  65. {
  66. if (!fwrite($file_handle, $data) and ($data != ''))
  67. $file_access_ok = false;
  68. else
  69. $file_open = true;
  70. }
  71. if ($file_open)
  72. fclose($file_handle);
  73. return $file_access_ok;
  74. }
  75. }
  76. ?>