Skip to content

Commit 9ebb698

Browse files
PhalconAdapter fixes
1 parent 73c3e05 commit 9ebb698

File tree

1 file changed

+53
-13
lines changed

1 file changed

+53
-13
lines changed

src/Bridges/Phalcon/PhalconAdapter.php

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,102 @@ class PhalconAdapter implements IDbal
1919
/** @var Pdo */
2020
private $conn;
2121

22-
22+
/**
23+
* @param Pdo $connection
24+
*/
2325
public function __construct(Pdo $connection)
2426
{
2527
$this->conn = $connection;
2628
$this->conn->connect();
2729
}
2830

29-
31+
/**
32+
* @param string $sql
33+
* @return array list of rows represented by assoc. arrays
34+
*/
3035
public function query($sql)
3136
{
3237
return $this->conn->fetchAll($sql);
3338
}
3439

35-
40+
/**
41+
* @param string $sql
42+
* @return int number of affected rows
43+
*/
3644
public function exec($sql)
3745
{
3846
$this->conn->execute($sql);
39-
$this->conn->affectedRows();
47+
return $this->conn->affectedRows();
4048
}
4149

4250

43-
public function escapeString($value)
51+
/**
52+
* @param string $value
53+
* @return string escaped string wrapped in quotes
54+
*/
55+
public function escapeString($value)
4456
{
45-
return $this->conn->getPdo()->quote($value, \PDO::PARAM_STR);
46-
}
47-
57+
return $this->conn->escapeString($value);
58+
}
4859

60+
/**
61+
* @param int $value
62+
* @return string
63+
*/
4964
public function escapeInt($value)
5065
{
5166
return (string)(int)$value;
5267
}
5368

5469

70+
/**
71+
* @param bool $value
72+
* @return string
73+
*/
5574
public function escapeBool($value)
5675
{
5776
return (string)(int)$value;
5877
}
5978

60-
79+
/**
80+
* @param DateTime $value
81+
* @return string
82+
* @throws ExecutionException
83+
*/
6184
public function escapeDateTime(DateTime $value)
6285
{
6386
return $this->conn->escapeString($this->formatDateTime($value));
6487
}
6588

66-
89+
/**
90+
* @param string $value
91+
* @return string
92+
* @throws ExecutionException
93+
*/
6794
public function escapeIdentifier($value)
6895
{
69-
return $this->conn->escapeIdentifier($value);
96+
if ($this->conn->getType() === self::TYPE_MYSQL) {
97+
return '`' . $value . '`';
98+
}
99+
100+
if ($this->conn->getType() === self::TYPE_PGSQL) {
101+
return '"' . $value . '"';
102+
}
103+
104+
throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.');
70105
}
71106

107+
/**
108+
* @param DateTime $value
109+
* @return string
110+
* @throws ExecutionException
111+
*/
72112
private function formatDateTime(DateTime $value)
73113
{
74114
if (in_array($this->conn->getType(), [self::TYPE_MYSQL, self::TYPE_PGSQL], true)) {
75115
return $value->format('Y-m-d H:i:s');
76-
} else {
77-
throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.');
78116
}
117+
118+
throw new ExecutionException('Unsupported type of \Phalcon\Db\Adapter\Pdo driver.');
79119
}
80120
}

0 commit comments

Comments
 (0)