/** * constructor **/ public function __construct() { $this->host = db_host(); $this->dbname = db_name(); $this->user = db_user(); $this->pass = db_psw(); $this->path = db_path(); switch (db_type()) { case "mysql": $dsn = 'mysql:host=' . $this->host . ";port=" . db_port() . ';dbname=' . $this->dbname; break; case "sqlite": $dsn = 'sqlite:' . $this->path . ';'; break; case "postgresql": $dsn = 'pgsql:host=' . $this->host . ";port=" . db_port() . ';dbname=' . $this->dbname; break; default: $dsn = 'mysql:host=' . $this->host . ";port=" . db_port() . ';dbname=' . $this->dbname; } $connection = new PDOConnection($dsn, $this->user, $this->pass, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::ATTR_TIMEOUT => 60 * 60 * 60 * 60, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => false]); $connection->connect(); $this->dbh = new Database($connection); }
/** * Delete entity * * @param array $item * * @return bool */ function flat_delete(array &$item) : bool { $attrs = $item['_entity']['attr']; $stmt = prep('DELETE FROM %s WHERE %s = :id', $item['_entity']['tab'], $attrs['id']['col']); $stmt->bindValue(':id', $item['_old']['id'], db_type($attrs['id'], $item['_old']['id'])); $stmt->execute(); return true; }