-
Notifications
You must be signed in to change notification settings - Fork 0
/
PdoWrapper.php
95 lines (81 loc) · 2.44 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/* * ********************************************************************
* DiscountCenter product developed. (2016-10-12)
* *
*
* CREATED BY MODULESGARDEN -> http://modulesgarden.com
* CONTACT -> contact@modulesgarden.com
*
*
* This software is furnished under a license and may be used and copied
* only in accordance with the terms of such license and with the
* inclusion of the above copyright notice. This software or any other
* copies thereof may not be provided or otherwise made available to any
* other person. No title to and ownership of the software is hereby
* transferred.
*
*
* ******************************************************************** */
namespace domainsReseller\module;
use Illuminate\Database\Capsule\Manager as DB;
/**
* Description of PdoWrapper
*
* @author Pawel Kopec <pawelk@modulesgarden.com>
* @version 1.0.0
*/
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();
}
}