| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- class Database
- {
- function __construct()
- {
- $this->customer_table = "customer";
- $this->category_table = "category";
- $this->product_table = "product";
- $this->price_table = "price";
- $this->priceset_table = "priceset";
- $this->tax_table = "tax";
- $this->bill_table = "bill";
- $this->bill_product_table = "bill_product";
- $this->tour_table = "tour";
- $this->assistant_table = "assistant";
- $this->group_table = "`group`";
- $this->customer_template_table = "customer_template";
- $this->ready = false;
- }
- function connectToDb()
- {
- $host = getenv('CLOUDRON_MYSQL_HOST');
- $user = getenv('CLOUDRON_MYSQL_USERNAME');
- $password = getenv('CLOUDRON_MYSQL_PASSWORD');
- $db = getenv('CLOUDRON_MYSQL_DATABASE');
- $port = getenv('CLOUDRON_MYSQL_PORT');
- $this->db_link = mysqli_connect($host, $user, $password);
- if(!$this->db_link)
- exit("Error: ".mysqli_connect_error());
- if(!mysqli_select_db($this->db_link, $db))
- exit("Error: selecting db");
- mysqli_set_charset($this->db_link, "latin1");
- $this->ready = TRUE;
- }
- function query($query)
- {
- if(!$this->ready)
- $this->connectToDb();
- if(!($result = mysqli_query($this->db_link, $query)))
- echo "Error: ".mysqli_error($this->db_link);
- return $result;
- }
- function fetchRows($result)
- {
- if(!$this->ready)
- $this->connectToDb();
- $all_rows = array();
- while($row = mysqli_fetch_row($result))
- $all_rows[] = $row;
- return $all_rows;
- }
- function writeToFile($path, $data)
- {
- $file_access_ok = true;
- $file_open = false;
- clearstatcache();
- if (file_exists($path))
- if (!is_writable($path))
- $file_access_ok = false;
- if ($file_access_ok and (!$file_handle = fopen($path, "w+b")))
- $file_access_ok = false;
- if ($file_access_ok)
- {
- if (!fwrite($file_handle, $data) and ($data != ''))
- $file_access_ok = false;
- else
- $file_open = true;
- }
- if ($file_open)
- fclose($file_handle);
- return $file_access_ok;
- }
- }
- ?>
|