| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- class Model {
- private $connection;
- public function __construct()
- {
- global $config;
-
- $this->connection = mysqli_connect($config['db_host'], $config['db_username'], $config['db_password'],$config['db_name']);
- //mysql_select_db($config['db_name'], $this->connection);
- mysqli_query($this->connection,"SET NAMES utf8");
- //mysqli_query($this->connection,"SET CHARACTER utf8");
- }
- public function escapeString($string)
- {
- return mysqli_real_escape_string($this->connection,$string);
- }
- public function escapeArray($array)
- {
- foreach ($array as $key => $value) {
- $array[$key] = mysqli_real_escape_string($this->connection, $value);
- }
- return $array;
- }
-
- public function to_bool($val)
- {
- return !!$val;
- }
-
- public function to_date($val)
- {
- return date('Y-m-d', $val);
- }
-
- public function to_time($val)
- {
- return date('H:i:s', $val);
- }
-
- public function to_datetime($val)
- {
- return date('Y-m-d H:i:s', $val);
- }
-
- public function query($qry,$force=false)
- {
- global $config;
- mysqli_select_db($this->connection,$config['db_name']);
- $result = mysqli_query($this->connection,$qry) or die(mysqli_error($this->connection));
-
- $resultObjects = array();
- if (mysqli_num_rows($result) > 0) {
- while ($row = mysqli_fetch_object($result)) $resultObjects[] = $row;
- }
-
- return $resultObjects;
- }
- public function execute($qry)
- {
- global $config;
- mysqli_select_db($this->connection,$config['db_name']);
- $exec = mysqli_query($this->connection,$qry) or die(mysqli_error($this->connection));
- return $exec;
- }
-
-
- public function getLastInsertID() {
- return mysqli_insert_id($this->connection);
- }
-
- }
- ?>
|