1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-24 10:53:17 +01:00

DibiMysqlDriver & DibiPostgreSql: escape() checks if resource is alive [Closes #46]

This commit is contained in:
David Grudl 2012-01-19 03:04:21 +01:00
parent 660a9db522
commit 5efb11d780
2 changed files with 12 additions and 0 deletions

View File

@ -300,9 +300,15 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
{ {
switch ($type) { switch ($type) {
case dibi::TEXT: case dibi::TEXT:
if (!is_resource($this->connection)) {
throw new DibiException('Lost connection to server.');
}
return "'" . mysql_real_escape_string($value, $this->connection) . "'"; return "'" . mysql_real_escape_string($value, $this->connection) . "'";
case dibi::BINARY: case dibi::BINARY:
if (!is_resource($this->connection)) {
throw new DibiException('Lost connection to server.');
}
return "_binary'" . mysql_real_escape_string($value, $this->connection) . "'"; return "_binary'" . mysql_real_escape_string($value, $this->connection) . "'";
case dibi::IDENTIFIER: case dibi::IDENTIFIER:

View File

@ -277,6 +277,9 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
switch ($type) { switch ($type) {
case dibi::TEXT: case dibi::TEXT:
if ($this->escMethod) { if ($this->escMethod) {
if (!is_resource($this->connection)) {
throw new DibiException('Lost connection to server.');
}
return "'" . pg_escape_string($this->connection, $value) . "'"; return "'" . pg_escape_string($this->connection, $value) . "'";
} else { } else {
return "'" . pg_escape_string($value) . "'"; return "'" . pg_escape_string($value) . "'";
@ -284,6 +287,9 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
case dibi::BINARY: case dibi::BINARY:
if ($this->escMethod) { if ($this->escMethod) {
if (!is_resource($this->connection)) {
throw new DibiException('Lost connection to server.');
}
return "'" . pg_escape_bytea($this->connection, $value) . "'"; return "'" . pg_escape_bytea($this->connection, $value) . "'";
} else { } else {
return "'" . pg_escape_bytea($value) . "'"; return "'" . pg_escape_bytea($value) . "'";