parent
c246e5d74b
commit
0a2d9b3b54
7 changed files with 98 additions and 123 deletions
@ -1,52 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* MINZ - Copyright 2011 Marien Fressinaud |
|
||||||
* Sous licence AGPL3 <http://www.gnu.org/licenses/> |
|
||||||
*/ |
|
||||||
|
|
||||||
abstract class Minz_Pdo extends PDO { |
|
||||||
public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
||||||
parent::__construct($dsn, $username, $passwd, $options); |
|
||||||
$this->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); |
|
||||||
} |
|
||||||
|
|
||||||
abstract public function dbType(); |
|
||||||
|
|
||||||
private $prefix = ''; |
|
||||||
public function prefix() { return $this->prefix; } |
|
||||||
public function setPrefix($prefix) { $this->prefix = $prefix; } |
|
||||||
|
|
||||||
private function autoPrefix($sql) { |
|
||||||
return str_replace('`_', '`' . $this->prefix, $sql); |
|
||||||
} |
|
||||||
|
|
||||||
protected function preSql($statement) { |
|
||||||
if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) { |
|
||||||
invalidateHttpCache(); |
|
||||||
} |
|
||||||
return $this->autoPrefix($statement); |
|
||||||
} |
|
||||||
|
|
||||||
public function lastInsertId($name = null) { |
|
||||||
if ($name != null) { |
|
||||||
$name = $this->preSql($name); |
|
||||||
} |
|
||||||
return parent::lastInsertId($name); |
|
||||||
} |
|
||||||
|
|
||||||
public function prepare($statement, $driver_options = array()) { |
|
||||||
$statement = $this->preSql($statement); |
|
||||||
return parent::prepare($statement, $driver_options); |
|
||||||
} |
|
||||||
|
|
||||||
public function exec($statement) { |
|
||||||
$statement = $this->preSql($statement); |
|
||||||
return parent::exec($statement); |
|
||||||
} |
|
||||||
|
|
||||||
public function query($query, $fetch_mode = null, ...$fetch_mode_args) { |
|
||||||
$query = $this->preSql($query); |
|
||||||
return $fetch_mode ? parent::query($query, $fetch_mode, ...$fetch_mode_args) : parent::query($query); |
|
||||||
} |
|
||||||
} |
|
@ -1,21 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* MINZ - Copyright 2011 Marien Fressinaud |
|
||||||
* Sous licence AGPL3 <http://www.gnu.org/licenses/> |
|
||||||
*/ |
|
||||||
|
|
||||||
class Minz_PdoMysql extends MinzPdo { |
|
||||||
public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
||||||
parent::__construct($dsn, $username, $passwd, $options); |
|
||||||
$this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); |
|
||||||
} |
|
||||||
|
|
||||||
public function dbType() { |
|
||||||
return 'mysql'; |
|
||||||
} |
|
||||||
|
|
||||||
public function lastInsertId($name = null) { |
|
||||||
return parent::lastInsertId(); //We discard the name, only used by PostgreSQL |
|
||||||
} |
|
||||||
} |
|
@ -1,22 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* MINZ - Copyright 2011 Marien Fressinaud |
|
||||||
* Sous licence AGPL3 <http://www.gnu.org/licenses/> |
|
||||||
*/ |
|
||||||
|
|
||||||
class Minz_PdoPgsql extends Minz_Pdo { |
|
||||||
public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
||||||
parent::__construct($dsn, $username, $passwd, $options); |
|
||||||
$this->exec("SET NAMES 'UTF8';"); |
|
||||||
} |
|
||||||
|
|
||||||
public function dbType() { |
|
||||||
return 'pgsql'; |
|
||||||
} |
|
||||||
|
|
||||||
protected function preSql($statement) { |
|
||||||
$statement = parent::preSql($statement); |
|
||||||
return str_replace(array('`', ' LIKE '), array('"', ' ILIKE '), $statement); |
|
||||||
} |
|
||||||
} |
|
@ -1,21 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* MINZ - Copyright 2011 Marien Fressinaud |
|
||||||
* Sous licence AGPL3 <http://www.gnu.org/licenses/> |
|
||||||
*/ |
|
||||||
|
|
||||||
class Minz_PdoSqlite extends Minz_Pdo { |
|
||||||
public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
||||||
parent::__construct($dsn, $username, $passwd, $options); |
|
||||||
$this->exec('PRAGMA foreign_keys = ON;'); |
|
||||||
} |
|
||||||
|
|
||||||
public function dbType() { |
|
||||||
return 'sqlite'; |
|
||||||
} |
|
||||||
|
|
||||||
public function lastInsertId($name = null) { |
|
||||||
return parent::lastInsertId(); //We discard the name, only used by PostgreSQL |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue