Merge branch 'dev' of dl:dylansserver into dev
[dylansserver.git] / model / model.php
1 <?php
2
3 class model {
4
5 private $config_file = '/etc/dylansserver.ini';
6 protected $model;
7 protected $recaptcha_publickey;
8 protected $recaptcha_privatekey;
9 public $title;
10 public $home_link;
11
12 public function __construct() {
13 $config = parse_ini_file($this->config_file, true);
14 $this->db = new mysqli(
15 $config['database']['domain'],
16 $config['database']['user'],
17 $config['database']['password'],
18 $config['database']['database']);
19 if (mysqli_connect_errno()) {
20 echo "Problem connecting to database: ";
21 echo mysqli_connect_error();
22 exit();
23 }
24 $this->recaptcha_publickey = $config['recaptcha']['publickey'];
25 $this->recaptcha_privatekey = $config['recaptcha']['privatekey'];
26 $this->title = $config['site']['default_title'];
27 $this->home_link = $config['site']['home_link'];
28 }
29
30 public function query() {
31 $args = func_get_args();
32 $statement = $this->db->prepare($args[0]);
33 $args = array_slice($args, 1);
34 call_user_func_array(array($statement, 'bind_param'), $args);
35 $statement->execute();
36 $return = array();
37 $statement->store_result();
38 $row = array();
39 $data = $statement->result_metadata();
40 $fields = array();
41 $fields[0] = &$statement;
42 while($field = $data->fetch_field()) {
43 $fields[] = &$row[$field->name];
44 }
45 call_user_func_array("mysqli_stmt_bind_result", $fields);
46 $i = 0;
47 while ($statement->fetch()) {
48 foreach ($row as $key=>$value) $return[$i][$key] = $value;
49 $i++;
50 }
51 $statement->free_result();
52 return $return;
53 }
54
55 }
56
57 ?>