From 029856b6fbefd0fb3cb72d2ed2ade7b6e1e13f55 Mon Sep 17 00:00:00 2001 From: homyak Date: Sat, 24 Feb 2024 00:26:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20'h?= =?UTF-8?q?tdocs/includes/pdoconnection.class.php'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/includes/pdoconnection.class.php | 164 ------------------------ 1 file changed, 164 deletions(-) delete mode 100644 htdocs/includes/pdoconnection.class.php diff --git a/htdocs/includes/pdoconnection.class.php b/htdocs/includes/pdoconnection.class.php deleted file mode 100644 index dfc2bd8..0000000 --- a/htdocs/includes/pdoconnection.class.php +++ /dev/null @@ -1,164 +0,0 @@ -_config = parse_ini_file(ROOT . '/../config/trackdirect.ini', true); - } - - /** - * Connect to the database. - */ - private function createConnection() - { - if (is_array($this->_config) && isset($this->_config['database'])) { - $databaseconfig = $this->_config['database']; - - if (!isset($databaseconfig['username'])) { - $databaseconfig['username'] = get_current_user(); - } - - try { - $this->_db = new PDO( - sprintf( - 'pgsql:dbname=%s;host=%s;port=%s;user=%s;password=%s', - $databaseconfig['database'], - $databaseconfig['host'], - $databaseconfig['port'], - $databaseconfig['username'], - $databaseconfig['password'] - ), null, null, - array( - PDO::ATTR_PERSISTENT => false, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION - ) - ); - } catch (PDOException $e) { - echo $e; - throw new Exception("Failed to connect to database."); - } - } else { - throw new Exception("Failed to parse database ini file."); - } - } - - /** - * Returnes a PDO db connection - * - * @return PDO - */ - private function getConnection() - { - if($this->_db === null) { - $this->createConnection(); - } - - return $this->_db; - } - - /** - * Executes an SQL statement, returning a result set as a PDOStatement object - * - * @param string $sql - * @return PDOStatement - */ - public function query($sql) - { - return $this->getConnection()->query($sql); - } - - /** - * Prepares a statement for execution and returns a statement object - * - * @param string $sql - * @return PDOStatement - */ - public function prepare($sql) - { - return $this->getConnection()->prepare($sql); - } - - /** - * Prepares a statement for execution and execute the prepared statement. Returnes the statment object - * - * @param string $sql - * @param array $arguments - * @return PDOStatement - */ - public function prepareAndExec($sql, array $arguments = array()) - { - $statement = $this->prepare($sql); - $statement->execute($arguments); - return $statement; - } - - /** - * Initiates a transaction. Turns off autocommit mode. Returns TRUE on success or FALSE on failure. - * - * @return boolean - */ - public function beginTransaction() - { - $this->getConnection()->beginTransaction(); - } - - /** - * Commits a transaction. Returns TRUE on success or FALSE on failure. - * - * @return boolean - */ - public function commit() - { - $this->getConnection()->commit(); - } - - /** - * Rolls back the current transaction (that was started by beginTransaction). Returns TRUE on success or FALSE on failure. - * - * @return boolean - */ - public function rollBack() - { - $this->getConnection()->rollBack(); - } - - /** - * Get the ID of the last inserted record. - * - * @param string $table - * @param string $column - * @return int - */ - public function lastInsertId($table, $column) - { - $suffix = '_' . $column . '_seq'; - - /* The max length of an identifier is 63 characters, - * if table_column_seq exceeds this postgres cuts the - * table name by default. */ - $table = substr($table, 0, 63 - (strlen($suffix))); - $sequenceName = $table . $suffix; - - return $this->getConnection()->lastInsertId($sequenceName); - } - - /** - * Returnes an initiated PDOConnection - * - * @return PDOConnection - */ - public static function getInstance() - { - if (self::$_singletonInstance === null) { - self::$_singletonInstance = new PDOConnection(); - } - - return self::$_singletonInstance; - } -}