1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Foolz\SphinxQL\Drivers\Pdo; |
4
|
|
|
|
5
|
|
|
use Foolz\SphinxQL\Drivers\ConnectionBase; |
6
|
|
|
use Foolz\SphinxQL\Drivers\MultiResultSet; |
7
|
|
|
use Foolz\SphinxQL\Drivers\ResultSet; |
8
|
|
|
use Foolz\SphinxQL\Exception\ConnectionException; |
9
|
|
|
use Foolz\SphinxQL\Exception\DatabaseException; |
10
|
|
|
use Foolz\SphinxQL\Exception\SphinxQLException; |
11
|
|
|
use PDO; |
12
|
|
|
use PDOException; |
13
|
|
|
|
14
|
|
|
class Connection extends ConnectionBase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @inheritdoc |
18
|
|
|
*/ |
19
|
|
|
public function query($query) |
20
|
|
|
{ |
21
|
|
|
$this->ensureConnection(); |
22
|
|
|
|
23
|
|
|
$statement = $this->connection->prepare($query); |
|
|
|
|
24
|
|
|
|
25
|
|
|
try { |
26
|
|
|
$statement->execute(); |
27
|
|
|
} catch (PDOException $exception) { |
28
|
|
|
throw new DatabaseException('[' . $exception->getCode() . '] ' . $exception->getMessage() . ' [' . $query . ']', |
29
|
|
|
(int)$exception->getCode(), $exception); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return new ResultSet(new ResultSetAdapter($statement)); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritdoc |
37
|
|
|
*/ |
38
|
|
|
public function connect() |
39
|
|
|
{ |
40
|
|
|
$params = $this->getParams(); |
41
|
|
|
|
42
|
|
|
$dsn = 'mysql:'; |
43
|
|
|
if (isset($params['host']) && $params['host'] != '') { |
44
|
|
|
$dsn .= 'host=' . $params['host'] . ';'; |
45
|
|
|
} |
46
|
|
|
if (isset($params['port'])) { |
47
|
|
|
$dsn .= 'port=' . $params['port'] . ';'; |
48
|
|
|
} |
49
|
|
|
if (isset($params['charset'])) { |
50
|
|
|
$dsn .= 'charset=' . $params['charset'] . ';'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (isset($params['socket']) && $params['socket'] != '') { |
54
|
|
|
$dsn .= 'unix_socket=' . $params['socket'] . ';'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
try { |
58
|
|
|
$con = new PDO($dsn); |
59
|
|
|
} catch (PDOException $exception) { |
60
|
|
|
throw new ConnectionException($exception->getMessage(), $exception->getCode(), $exception); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->connection = $con; |
64
|
|
|
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
65
|
|
|
|
66
|
|
|
return true; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return bool |
71
|
|
|
* @throws ConnectionException |
72
|
|
|
*/ |
73
|
|
|
public function ping() |
74
|
|
|
{ |
75
|
|
|
$this->ensureConnection(); |
76
|
|
|
|
77
|
|
|
return $this->connection !== null; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @inheritdoc |
82
|
|
|
*/ |
83
|
|
|
public function multiQuery(array $queue) |
84
|
|
|
{ |
85
|
|
|
$this->ensureConnection(); |
86
|
|
|
|
87
|
|
|
if (count($queue) === 0) { |
88
|
|
|
throw new SphinxQLException('The Queue is empty.'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
try { |
92
|
|
|
$statement = $this->connection->query(implode(';', $queue)); |
93
|
|
|
} catch (PDOException $exception) { |
94
|
|
|
throw new DatabaseException($exception->getMessage() .' [ '.implode(';', $queue).']', $exception->getCode(), $exception); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return new MultiResultSet(new MultiResultSetAdapter($statement)); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @inheritdoc |
102
|
|
|
*/ |
103
|
|
|
public function escape($value) |
104
|
|
|
{ |
105
|
|
|
$this->ensureConnection(); |
106
|
|
|
|
107
|
|
|
return $this->connection->quote($value); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.