-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathmodel.php
More file actions
72 lines (57 loc) · 1.38 KB
/
Copy pathmodel.php
File metadata and controls
72 lines (57 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
class Model extends PDO{
private $connection;
public function __construct(){
global $config;
try{
$dsn = "mysql:dbname={$config['db_name']};host={$config['db_host']}";
$this->connection = parent::__construct($dsn, $config['db_username'], $config['db_password']);
parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
return $e->getMessage();
}
}
//deprecated
public function escapeString($string){
return mysql_real_escape_string($string);
}
//deprecated
public function escapeArray($array){
array_walk_recursive($array, create_function('&$v', '$v = mysql_real_escape_string($v);'));
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, $params=array()){
try{
$pdo = $this->prepare($qry);
$pdo->execute($params);
return $pdo->fetchAll(PDO::FETCH_OBJ);
}
catch(PDOException $e){
return $e->getMessage();
}
}
public function execute($qry, $params=array()){
try{
$pdo = $this->prepare($qry);
$pdo->execute($params);
return $pdo->rowCount();
}
catch(PDOException $e){
return $e->getMessage();
}
}
}
?>