dbTarget)) { $this->selectInstance(); } if (!isset($this->connection)) { $this->connection = new PDO($this->dbTarget, Olio::$config['dbUser'], Olio::$config['dbPass'], array(PDO::ATTR_PERSISTENT => true)); $this->connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $this->connection->setAttribute( // throw exception on error. PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (!$this->connection) throw new Exception("Unable to connect " . $this->dbTarget."!"); } } function query() { if (func_num_args() > 1) { $args = func_get_args(); $sql = $args[0]; unset($args[0]); // remove the sql $args = array_values($args); // and reset the array index } else { $sql = func_get_arg(0); } $this->ensureConnection(); if (isset($args)) { $stmt = $this->connection->prepare($sql); $stmt->execute($args); return new PDOResult($this, $stmt); } else { $result = $this->connection->query($sql); return new PDOResult($this, $result); } } function exec() { if (func_num_args() > 1) { $args = func_get_args(); $sql = $args[0]; unset($args[0]); // remove the sql $args = array_values($args); // and reset the array index } else { $sql = func_get_arg(0); } $this->ensureConnection(); if (isset($args)) { $stmt = $this->connection->prepare($sql); $stmt->execute($args); $rows = $stmt->rowCount(); return $rows; } else { return $this->connection->exec($sql); } } function beginTransaction() { $this->ensureConnection(); $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, false); $this->connection->beginTransaction(); } function commit() { $this->connection->commit(); $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, true); } function rollback() { $this->connection->rollBack(); $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, true); } function __destruct() { if (isset($this->connection)) { unset($this->connection); } } } ?>