initial files for igorcms
[igorcms.git] / includes / class / dbal_mysqli.php
blob12d58b2f99c20fdaeee03af11bf4a2e7bd8c7efd
1 <?php
3 if (!defined('ROOT_PATH'))
5 exit;
8 require(ROOT_PATH . 'includes/class/dbal.' . PHP_EXT);
10 class dbal_mysqli extends dbal
12 public function sql_connect($dbhost, $dbport, $dbname, $dbuser, $dbpass)
14 if (!$this->db_conn = mysqli_connect($dbhost . (!empty($dbport) ? ":$dbport" : ''), $dbuser, $dbpass))
16 throw new ErrorException('dbal: failed to connect to database');
19 mysqli_query($this->db_conn, "SET NAMES 'utf8'");
21 if (!mysqli_select_db($this->db_conn, $dbname))
23 throw new ErrorException('dbal: failed to select db');
27 public function sql_query($sql)
29 $result = mysqli_query($this->conn_id, $sql);
31 if (!$result)
33 throw new ErrorException("dbal: query failed\n\n" . mysqli_error($this->conn_id));
36 return $result;
39 public function sql_fetchrow($result)
41 return mysqli_fetch_assoc($this->conn_id, $result);
44 public function sql_freeresult($result)
46 return mysqli_free_result($result);
49 public function sql_close()
51 return mysqli_close($this->conn_id);