This repository has been archived by the owner on Oct 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
PdoWrapper.php
71 lines (58 loc) · 1.61 KB
/
PdoWrapper.php
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
<?php
namespace domainsReseller\module;
use Illuminate\Database\Capsule\Manager as DB;
class PdoWrapper
{
public static function query($query, $params = array())
{
$statement = DB::connection()
->getPdo()
->prepare($query);
$statement->execute($params);
return $statement;
}
public static function realEscapeString($string)
{
return substr(DB::connection()->getPdo()->quote($string), 1, -1);
}
public static function fetchAssoc($query)
{
return $query->fetch(\PDO::FETCH_ASSOC);
}
public static function fetchArray($query)
{
return $query->fetch(\PDO::FETCH_BOTH);
}
public static function fetchObject($query)
{
return $query->fetch(\PDO::FETCH_OBJ);
}
public static function numRows($query)
{
$query->fetch(\PDO::FETCH_BOTH);
return $query->rowCount();
}
public static function insertId()
{
return DB::connection()
->getPdo()
->lastInsertId();
}
public static function rowCount(\PDOStatement $query)
{
return $query->rowCount();
}
public static function query_safe($query, $params = false)
{
if ($params) {
foreach ($params as &$v) {
$v = self::realEscapeString($v);
}
$query = vsprintf(str_replace("?", "'%s'", $query), $params);
}
return self::query($query);
}
public static function getError(\PDOStatement $query){
return $query->errorInfo();
}
}