26 defined(
'LGV_DB_CATCHER' ) or die ( 'Cannot Execute Directly' );
36 var $driver_type = NULL;
38 var $class_description = NULL;
40 var $last_insert = NULL;
42 var $owner_instance = NULL;
45 private $fetchMode = PDO::FETCH_ASSOC;
64 $this->class_description =
'A class for managing PDO access to the databases.';
67 $this->driver_type = $driver;
68 $this->last_insert = NULL;
70 $dsn = $driver .
':host=' . $host .
';dbname=' . $database ;
72 $this->_pdo =
new PDO($dsn, $user, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND =>
"SET NAMES 'utf8'"));
73 $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
74 $this->_pdo->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
75 $this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,
true);
76 if (strlen($charset) > 0) {
77 self::preparedExec(
'SET NAMES :charset', array(
':charset' => $charset),
false);
79 }
catch (PDOException $exception) {
80 throw new Exception(__METHOD__ .
'() ' . $exception->getMessage());
100 $this->last_insert = NULL;
102 if (
'pgsql' == $this->driver_type) {
103 if (strpos($sql,
'RETURNING id;')) {
104 $response = $this->preparedQuery($sql, $params);
105 $this->last_insert = intval($response[0][
'id']);
110 $sql = str_replace(
' RETURNING id',
'', $sql);
112 if (method_exists(
'CO_Config',
'call_low_level_log_handler_function')) {
113 CO_Config::call_low_level_log_handler_function(isset($this->owner_instance) ? $this->owner_instance->access_object->get_login_id() : 0, $sql, $params);
115 $this->_pdo->beginTransaction();
116 $stmt = $this->_pdo->prepare($sql);
117 $stmt->execute($params);
118 if (
'pgsql' != $this->driver_type) {
119 $this->last_insert = $this->_pdo->lastInsertId();
121 $this->_pdo->commit();
124 }
catch (PDOException $exception) {
125 $this->last_insert = NULL;
126 $this->_pdo->rollback();
127 throw new Exception(__METHOD__ .
'() ' . $exception->getMessage());
151 $fetchKeyPair =
false
153 $this->last_insert = NULL;
156 if (method_exists(
'CO_Config',
'call_low_level_log_handler_function')) {
157 CO_Config::call_low_level_log_handler_function(isset($this->owner_instance) ? $this->owner_instance->access_object->get_login_id() : 0, $sql, $params);
159 $this->_pdo->beginTransaction();
160 $stmt = $this->_pdo->prepare($sql);
161 $stmt->setFetchMode($this->fetchMode);
162 $stmt->execute($params);
163 $this->_pdo->commit();
168 $ret = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
170 $ret = $stmt->fetchAll();
174 }
catch (PDOException $exception) {
175 $this->last_insert = NULL;
176 $this->_pdo->rollback();
177 throw new Exception(__METHOD__ .
'() ' . $exception->getMessage());
This class provides a genericized interface to the PHP PDO toolkit.
preparedQuery( $sql, $params=array(), $fetchKeyPair=false)
Wrapper for preparing and executing a PDOStatement that returns a resultset e.g. SELECT SQL statement...
preparedExec( $sql, $params=array())
Wrapper for preparing and executing a PDOStatement that does not return a resultset e....
__construct( $driver, $host, $database, $user=NULL, $password=NULL, $charset=NULL)
Initializes connection param class members.