Browse Source
postgreSQL Connector
postgreSQL Connector
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@76 4cb57b5f-5bbd-dd11-951b-001d605cbbc5master
akulikov
16 years ago
1 changed files with 110 additions and 0 deletions
@ -0,0 +1,110 @@ |
|||
<?php |
|||
/** |
|||
* Класс базы данных. |
|||
* Возвращает идентификатор соединения |
|||
* |
|||
* @copyright |
|||
* @link |
|||
* @package Majestic |
|||
* @subpackage DB |
|||
* @since |
|||
* @version SVN: $Id$ |
|||
* @filesource $URL$ |
|||
*/ |
|||
class DBConnector |
|||
{ |
|||
static private $handlers = array(); |
|||
static public $queries = array(); |
|||
|
|||
/** |
|||
* Запрещаем new и клонирование |
|||
*/ |
|||
private function __construct(){} |
|||
|
|||
private function __clone(){} |
|||
|
|||
/** |
|||
* Получение соединения. |
|||
* Если соединение с такими параметрами уже есть - новое не создается. |
|||
* |
|||
* @param array $db_settings - массив настроек |
|||
* @return resource - идентификатор соединения |
|||
*/ |
|||
static public function getConnect($db_settings) |
|||
{ |
|||
$handler_name = self::getConnectionName($db_settings); |
|||
|
|||
if (isset(self::$handlers[$handler_name])) { |
|||
return self::$handlers[$handler_name]; |
|||
} |
|||
|
|||
if (!$handler = pg_connect("host='".$db_settings['host']."' dbname='".$db_settings['database']."' user='".$db_settings['user'].'" password="'.$db_settings['password']."'")) { |
|||
throw new MJException('Can\'t connect to DB '.pg_last_error($handler), 2); |
|||
} |
|||
|
|||
return self::$handlers[$handler_name] = $handler; |
|||
} |
|||
|
|||
static protected function getConnectionName($db_settings) |
|||
{ |
|||
return $db_settings['host'] . '-' . $db_settings['database']; |
|||
} |
|||
|
|||
/////////
|
|||
|
|||
static public function query($handler, $sql) |
|||
{ |
|||
return pg_query($handler, $sql); |
|||
} |
|||
|
|||
static public function escape($handler, $str) |
|||
{ |
|||
return pg_escape_string($str); |
|||
} |
|||
|
|||
static public function error($handler) |
|||
{ |
|||
return pg_last_error($handler); |
|||
} |
|||
|
|||
static public function free($result) |
|||
{ |
|||
return pg_free_result($result); |
|||
} |
|||
|
|||
static public function fetchObject($result, $class_name = false) |
|||
{ |
|||
return $class_name ? pg_fetch_object($result, null, $class_name) : pg_fetch_object($result); |
|||
} |
|||
|
|||
static public function numRows($result) |
|||
{ |
|||
return pg_num_rows($result); |
|||
} |
|||
|
|||
static public function affectedRows($handler) |
|||
{ |
|||
return pg_affected_rows($handler); |
|||
} |
|||
|
|||
static public function getId($handler) |
|||
{ |
|||
return pg_last_oid($handler); |
|||
} |
|||
|
|||
static public function autocommit($handler, $switch) |
|||
{ |
|||
throw new MJException('Autocommit disabled for postgreSQL Connector' ,1); |
|||
} |
|||
|
|||
static public function commit($handler) |
|||
{ |
|||
throw new MJException('Commit disabled for postgreSQL Connector' ,1); |
|||
} |
|||
|
|||
static public function rollback($handler) |
|||
{ |
|||
throw new MJException('Rollback disabled for postgreSQL Connector' ,1); |
|||
} |
|||
} |
|||
?>
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue