forked from stefangabos/Zebra_Session
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMysqliConnection.php
More file actions
63 lines (47 loc) · 1.12 KB
/
Copy pathMysqliConnection.php
File metadata and controls
63 lines (47 loc) · 1.12 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
<?php
namespace steamegg\SessionDatabase\Connection;
class MysqliConnection implements IConnection {
protected $db;
function __construct(\mysqli $db){
$this->db = $db;
}
function affectedRows(){
return $this->db->affected_rows;
}
function error(){
return $this->db->error;
}
function query($query){
return $this->db->query($query);
}
function quote($string){
return sprintf("'%s'", $this->escape($string));
}
protected function escape($string){
return $this->db->real_escape_string($string);
}
function getLock($name, $timeout){
$sql = sprintf("SELECT GET_LOCK('%s', '%s')",
$this->escape($name),
$this->escape($timeout));
$result = $this->query($sql);
if(!$result)
return FALSE;
if(mysqli_num_rows($result) != 1)
return FALSE;
$row = mysqli_fetch_array($result);
if($row[0] !== "1")
return FALSE;
return TRUE;
}
function releaseLock($name){
$sql = sprintf("SELECT RELEASE_LOCK('%s')", $this->escape($name));
$this->query($sql);
}
function fetchRow($result){
return mysqli_fetch_assoc($result);
}
function ping(){
return $this->db->ping();
}
}