Hoa central
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Hoa\Database\Layer\Pdo\Pdo Class Reference
Inheritance diagram for Hoa\Database\Layer\Pdo\Pdo:

Public Member Functions

 __construct ($dsn, $username, $password, Array $driverOptions=[])
 
 beginTransaction ()
 
 commit ()
 
 rollBack ()
 
 lastInsertId ($name=null)
 
 prepare ($statement, Array $options=[])
 
 quote ($string=null, $type=-1)
 
 query ($statement)
 
 errorCode ()
 
 errorInfo ()
 
 getAvailableDrivers ()
 
 setAttributes (Array $attributes)
 
 setAttribute ($attribute, $value)
 
 getAttributes ()
 
 getAttribute ($attribute)
 

Protected Member Functions

 setConnection (\PDO $connection)
 
 getConnection ()
 

Protected Attributes

 $_connection = null
 

Detailed Description

Class .

Wrap PDO.

Definition at line 50 of file Pdo.php.

Constructor & Destructor Documentation

Hoa\Database\Layer\Pdo\Pdo::__construct (   $dsn,
  $username,
  $password,
Array  $driverOptions = [] 
)

Create a DAL instance, representing a connection to a database.

Parameters
string$dsnThe DSN of database.
string$usernameThe username to connect to database.
string$passwordThe password to connect to database.
array$driverOptionsThe driver options.
Returns
void
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 71 of file Pdo.php.

76  {
77  if (false === extension_loaded('pdo')) {
78  throw new Database\Exception(
79  'The module PDO is not enabled.',
80  0
81  );
82  }
83 
84  $connection = null;
85 
86  try {
87  $connection = new \PDO($dsn, $username, $password, $driverOptions);
88  } catch (\PDOException $e) {
89  throw new Database\Exception(
90  $e->getMessage(),
91  $e->getCode(),
92  null,
93  $e
94  );
95  }
96 
97  $this->setConnection($connection);
98 
99  return;
100  }
setConnection(\PDO $connection)
Definition: Pdo.php:108

Here is the call graph for this function:

Member Function Documentation

Hoa\Database\Layer\Pdo\Pdo::beginTransaction ( )

Initiate a transaction.

Returns
bool
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 140 of file Pdo.php.

141  {
142  return $this->getConnection()->beginTransaction();
143  }

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::commit ( )

Commit a transaction.

Returns
bool
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 151 of file Pdo.php.

152  {
153  return $this->getConnection()->commit();
154  }

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::errorCode ( )

Fetch the SQLSTATE associated with the last operation on the database handle.

Returns
string
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 257 of file Pdo.php.

258  {
259  return $this->getConnection()->errorCode();
260  }

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::errorInfo ( )

Fetch extends error information associated with the last operation on the database handle.

Returns
array
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 269 of file Pdo.php.

270  {
271  return $this->getConnection()->errorInfo();
272  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Database\Layer\Pdo\Pdo::getAttribute (   $attribute)

Retrieve a database connection attribute.

Parameters
string$attributeAttribute name.
Returns
mixed
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 354 of file Pdo.php.

355  {
356  return
357  $this
358  ->getConnection()
359  ->getAttribute(constant('\PDO::ATTR_' . $attribute));
360  }

Here is the caller graph for this function:

Hoa\Database\Layer\Pdo\Pdo::getAttributes ( )

Retrieve all database connection attributes.

Returns
array
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 322 of file Pdo.php.

323  {
324  $out = [];
325  $attributes = [
326  0 => 'AUTOCOMMIT',
327  1 => 'CASE',
328  2 => 'CLIENT_VERSION',
329  3 => 'CONNECTION_STATUS',
330  4 => 'DRIVER_NAME',
331  5 => 'ERRMODE',
332  6 => 'ORACLE_NULLS',
333  7 => 'PERSISTENT',
334  8 => 'PREFETCH',
335  9 => 'SERVER_INFO',
336  10 => 'SERVER_VERSION',
337  11 => 'TIMEOUT'
338  ];
339 
340  foreach ($attributes as $attribute) {
341  $out[$attribute] = $this->getAttribute($attribute);
342  }
343 
344  return $out;
345  }
getAttribute($attribute)
Definition: Pdo.php:354

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::getAvailableDrivers ( )

Return an array of available drivers.

Returns
array
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 280 of file Pdo.php.

281  {
282  return $this->getConnection()->getAvailableDrivers();
283  }

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::getConnection ( )
protected

Get the connection instance.

Returns
PDO
Exceptions

Definition at line 122 of file Pdo.php.

123  {
124  if (null === $this->_connection) {
125  throw new Database\Exception(
126  'Cannot return a null connection.',
127  1
128  );
129  }
130 
131  return $this->_connection;
132  }

Here is the caller graph for this function:

Hoa\Database\Layer\Pdo\Pdo::lastInsertId (   $name = null)

Return the ID of the last inserted row or sequence value.

Parameters
string$nameName of sequence object (needed for some driver).
Returns
string
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 175 of file Pdo.php.

176  {
177  if (null === $name) {
178  return $this->getConnection()->lastInsertId();
179  }
180 
181  return $this->getConnection()->lastInsertId($name);
182  }

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::prepare (   $statement,
Array  $options = [] 
)

Prepare a statement for execution and returns a statement object.

Parameters
string$statementThis must be a valid SQL statement for the target database server.
array$optionsOptions to set attributes values for the Layer Statement.
Returns
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 194 of file Pdo.php.

195  {
196  $handle = $this->getConnection()->prepare($statement);
197 
198  if (!($handle instanceof \PDOStatement)) {
199  throw new Database\Exception(
200  '%3$s (%1$s/%2$d).',
201  2,
202  $this->errorInfo()
203  );
204  }
205 
206  return new Statement($handle);
207  }

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::query (   $statement)

Execute an SQL statement, returning a result set as a object.

Parameters
string$statementThe SQL statement to prepare and execute.
Returns
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 235 of file Pdo.php.

236  {
237  $handle = $this->getConnection()->query($statement);
238 
239  if (!($handle instanceof \PDOStatement)) {
240  throw new Database\Exception(
241  '%3$s (%1$s/%2$d).',
242  3,
243  $this->errorInfo()
244  );
245  }
246 
247  return new Statement($handle);
248  }

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::quote (   $string = null,
  $type = -1 
)

Quote a sting for use in a query.

Parameters
string$stringThe string to be quoted.
int$typeProvide a data type hint for drivers that have alternate quoting styles.
Returns
string
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 218 of file Pdo.php.

219  {
220  if ($type < 0) {
221  return $this->getConnection()->quote($string);
222  }
223 
224  return $this->getConnection()->quote($string, $type);
225  }

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::rollBack ( )

Roll back a transaction.

Returns
bool
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 162 of file Pdo.php.

163  {
164  return $this->getConnection()->rollBack();
165  }

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::setAttribute (   $attribute,
  $value 
)

Set a specific attribute.

Parameters
mixed$attributeAttribute name.
mixed$valueAttribute value.
Returns
mixed
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 311 of file Pdo.php.

312  {
313  return $this->getConnection()->setAttribute($attribute, $value);
314  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Database\Layer\Pdo\Pdo::setAttributes ( Array  $attributes)

Set attributes.

Parameters
array$attributesAttributes values.
Returns
array
Exceptions

Implements Hoa\Database\IDal\Wrapper.

Definition at line 292 of file Pdo.php.

293  {
294  $out = true;
295 
296  foreach ($attributes as $attribute => $value) {
297  $out &= $this->setAttribute($attribute, $value);
298  }
299 
300  return (bool) $out;
301  }
setAttribute($attribute, $value)
Definition: Pdo.php:311

Here is the call graph for this function:

Hoa\Database\Layer\Pdo\Pdo::setConnection ( \PDO  $connection)
protected

Set the connection.

Parameters
\PDO$connectionThe PDO instance.
Returns

Definition at line 108 of file Pdo.php.

109  {
110  $old = $this->_connection;
111  $this->_connection = $connection;
112 
113  return $old;
114  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Database\Layer\Pdo\Pdo::$_connection = null
protected

Definition at line 57 of file Pdo.php.


The documentation for this class was generated from the following file: