| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- class Database
- {
- function Database()
- {
- $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->bill_import_table = "bill_import";
- $this->bill_product_import_table = "bill_product_import";
- $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, $db, $port);
- if(!$this->db_link) {
- echo "Error: ".mysqli_connect_error();
- exit(1);
- }
- $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);
- }
- }
- ?>
|