Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Db_Adapter_Pdo_Abstract Class Reference
Inheritance diagram for Zend_Db_Adapter_Pdo_Abstract:
Zend_Db_Adapter_Abstract Zend_Db_Adapter_Pdo_Ibm Zend_Db_Adapter_Pdo_Mssql Zend_Db_Adapter_Pdo_Mysql Zend_Db_Adapter_Pdo_Oci Zend_Db_Adapter_Pdo_Pgsql Zend_Db_Adapter_Pdo_Sqlite Mysql Mysql

Public Member Functions

 isConnected ()
 
 closeConnection ()
 
 prepare ($sql)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
 query ($sql, $bind=array())
 
 exec ($sql)
 
 setFetchMode ($mode)
 
 supportsParameters ($type)
 
 getServerVersion ()
 
- Public Member Functions inherited from Zend_Db_Adapter_Abstract
 __construct ($config)
 
 getConnection ()
 
 getConfig ()
 
 setProfiler ($profiler)
 
 getProfiler ()
 
 getStatementClass ()
 
 setStatementClass ($class)
 
 query ($sql, $bind=array())
 
 beginTransaction ()
 
 commit ()
 
 rollBack ()
 
 insert ($table, array $bind)
 
 update ($table, array $bind, $where='')
 
 delete ($table, $where='')
 
 select ()
 
 getFetchMode ()
 
 fetchAll ($sql, $bind=array(), $fetchMode=null)
 
 fetchRow ($sql, $bind=array(), $fetchMode=null)
 
 fetchAssoc ($sql, $bind=array())
 
 fetchCol ($sql, $bind=array())
 
 fetchPairs ($sql, $bind=array())
 
 fetchOne ($sql, $bind=array())
 
 quote ($value, $type=null)
 
 quoteInto ($text, $value, $type=null, $count=null)
 
 quoteIdentifier ($ident, $auto=false)
 
 quoteColumnAs ($ident, $alias, $auto=false)
 
 quoteTableAs ($ident, $alias=null, $auto=false)
 
 getQuoteIdentifierSymbol ()
 
 lastSequenceId ($sequenceName)
 
 nextSequenceId ($sequenceName)
 
 foldCase ($key)
 
 __sleep ()
 
 __wakeup ()
 
 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 isConnected ()
 
 closeConnection ()
 
 prepare ($sql)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
 setFetchMode ($mode)
 
 limit ($sql, $count, $offset=0)
 
 supportsParameters ($type)
 
 getServerVersion ()
 

Protected Member Functions

 _dsn ()
 
 _connect ()
 
 _quote ($value)
 
 _beginTransaction ()
 
 _commit ()
 
 _rollBack ()
 
- Protected Member Functions inherited from Zend_Db_Adapter_Abstract
 _checkRequiredOptions (array $config)
 
 _whereExpr ($where)
 
 _quote ($value)
 
 _quoteIdentifierAs ($ident, $alias=null, $auto=false, $as=' AS ')
 
 _quoteIdentifier ($value, $auto=false)
 
 _connect ()
 
 _beginTransaction ()
 
 _commit ()
 
 _rollBack ()
 

Protected Attributes

 $_defaultStmtClass = 'Zend_Db_Statement_Pdo'
 
- Protected Attributes inherited from Zend_Db_Adapter_Abstract
 $_config = array()
 
 $_fetchMode = Zend_Db::FETCH_ASSOC
 
 $_profiler
 
 $_defaultStmtClass = 'Zend_Db_Statement'
 
 $_defaultProfilerClass = 'Zend_Db_Profiler'
 
 $_connection = null
 
 $_caseFolding = Zend_Db::CASE_NATURAL
 
 $_autoQuoteIdentifiers = true
 
 $_numericDataTypes
 
 $_allowSerialization = true
 
 $_autoReconnectOnUnserialize = false
 

Detailed Description

Definition at line 45 of file Abstract.php.

Member Function Documentation

◆ _beginTransaction()

_beginTransaction ( )
protected

Begin a transaction.

Definition at line 302 of file Abstract.php.

303  {
304  $this->_connect();
305  $this->_connection->beginTransaction();
306  }

◆ _commit()

_commit ( )
protected

Commit a transaction.

Definition at line 311 of file Abstract.php.

312  {
313  $this->_connect();
314  $this->_connection->commit();
315  }

◆ _connect()

_connect ( )
protected

Creates a PDO object and connects to the database.

Returns
void
Exceptions
Zend_Db_Adapter_Exception
See also
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception

Definition at line 87 of file Abstract.php.

88  {
89  // if we already have a PDO object, no need to re-connect.
90  if ($this->_connection) {
91  return;
92  }
93 
94  // get the dsn first, because some adapters alter the $_pdoType
95  $dsn = $this->_dsn();
96 
97  // check for PDO extension
98  if (!extension_loaded('pdo')) {
102  #require_once 'Zend/Db/Adapter/Exception.php';
103  throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
104  }
105 
106  // check the PDO driver is available
107  if (!in_array($this->_pdoType, PDO::getAvailableDrivers())) {
111  #require_once 'Zend/Db/Adapter/Exception.php';
112  throw new Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed');
113  }
114 
115  // create PDO connection
116  $q = $this->_profiler->queryStart('connect', Zend_Db_Profiler::CONNECT);
117 
118  // add the persistence flag if we find it in our config array
119  if (isset($this->_config['persistent']) && ($this->_config['persistent'] == true)) {
120  $this->_config['driver_options'][PDO::ATTR_PERSISTENT] = true;
121  }
122 
123  try {
124  $this->_connection = new PDO(
125  $dsn,
126  $this->_config['username'],
127  $this->_config['password'],
128  $this->_config['driver_options']
129  );
130 
131  $this->_profiler->queryEnd($q);
132 
133  // set the PDO connection to perform case-folding on array keys, or not
134  $this->_connection->setAttribute(PDO::ATTR_CASE, $this->_caseFolding);
135 
136  // always use exceptions.
137  $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
138 
139  } catch (PDOException $e) {
143  #require_once 'Zend/Db/Adapter/Exception.php';
144  throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
145  }
146 
147  }

◆ _dsn()

_dsn ( )
protected

Creates a PDO DSN for the adapter from $this->_config settings.

Returns
string

Definition at line 60 of file Abstract.php.

61  {
62  // baseline of DSN parts
63  $dsn = $this->_config;
64 
65  // don't pass the username, password, charset, persistent and driver_options in the DSN
66  unset($dsn['username']);
67  unset($dsn['password']);
68  unset($dsn['options']);
69  unset($dsn['charset']);
70  unset($dsn['persistent']);
71  unset($dsn['driver_options']);
72 
73  // use all remaining parts in the DSN
74  foreach ($dsn as $key => $val) {
75  $dsn[$key] = "$key=$val";
76  }
77 
78  return $this->_pdoType . ':' . implode(';', $dsn);
79  }

◆ _quote()

_quote (   $value)
protected

Quote a raw string.

Parameters
string$valueRaw string
Returns
string Quoted string

Definition at line 290 of file Abstract.php.

291  {
292  if (is_int($value) || is_float($value)) {
293  return $value;
294  }
295  $this->_connect();
296  return $this->_connection->quote($value);
297  }
$value
Definition: gender.phtml:16

◆ _rollBack()

_rollBack ( )
protected

Roll-back a transaction.

Definition at line 320 of file Abstract.php.

320  {
321  $this->_connect();
322  $this->_connection->rollBack();
323  }

◆ closeConnection()

closeConnection ( )

Force the connection to close.

Returns
void

Definition at line 164 of file Abstract.php.

165  {
166  $this->_connection = null;
167  }

◆ exec()

exec (   $sql)

Executes an SQL statement and return the number of affected rows

Parameters
mixed$sqlThe SQL statement with placeholders. May be a string or Zend_Db_Select.
Returns
integer Number of rows that were modified or deleted by the SQL statement
See also
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception

Definition at line 256 of file Abstract.php.

257  {
258  if ($sql instanceof Zend_Db_Select) {
259  $sql = $sql->assemble();
260  }
261 
262  try {
263  $affected = $this->getConnection()->exec($sql);
264 
265  if ($affected === false) {
266  $errorInfo = $this->getConnection()->errorInfo();
270  #require_once 'Zend/Db/Adapter/Exception.php';
271  throw new Zend_Db_Adapter_Exception($errorInfo[2]);
272  }
273 
274  return $affected;
275  } catch (PDOException $e) {
279  #require_once 'Zend/Db/Adapter/Exception.php';
280  throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
281  }
282  }

◆ getServerVersion()

getServerVersion ( )

Retrieve server version in PHP style

Returns
string

Definition at line 384 of file Abstract.php.

385  {
386  $this->_connect();
387  try {
388  $version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
389  } catch (PDOException $e) {
390  // In case of the driver doesn't support getting attributes
391  return null;
392  }
393  $matches = null;
394  if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
395  return $matches[1];
396  } else {
397  return null;
398  }
399  }

◆ isConnected()

isConnected ( )

Test if a connection is active

Returns
boolean

Definition at line 154 of file Abstract.php.

155  {
156  return ((bool) ($this->_connection instanceof PDO));
157  }

◆ lastInsertId()

lastInsertId (   $tableName = null,
  $primaryKey = null 
)

Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.

As a convention, on RDBMS brands that support sequences (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence from the arguments and returns the last id generated by that sequence. On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method returns the last value generated for such a column, and the table name argument is disregarded.

On RDBMS brands that don't support sequences, $tableName and $primaryKey are ignored.

Parameters
string$tableNameOPTIONAL Name of table.
string$primaryKeyOPTIONAL Name of primary key column.
Returns
string

Definition at line 206 of file Abstract.php.

207  {
208  $this->_connect();
209  return $this->_connection->lastInsertId();
210  }

◆ prepare()

prepare (   $sql)

Prepares an SQL statement.

Parameters
string$sqlThe SQL statement with placeholders.
array$bindAn array of data to bind to the placeholders.
Returns
PDOStatement

Definition at line 176 of file Abstract.php.

177  {
178  $this->_connect();
179  $stmtClass = $this->_defaultStmtClass;
180  if (!class_exists($stmtClass)) {
181  #require_once 'Zend/Loader.php';
182  Zend_Loader::loadClass($stmtClass);
183  }
184  $stmt = new $stmtClass($this, $sql);
185  $stmt->setFetchMode($this->_fetchMode);
186  return $stmt;
187  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52

◆ query()

query (   $sql,
  $bind = array() 
)

Special handling for PDO query(). All bind parameter names must begin with ':'

Parameters
string | Zend_Db_Select$sqlThe SQL statement with placeholders.
array$bindAn array of data to bind to the placeholders.
Returns
Zend_Db_Statement_Pdo
Exceptions
Zend_Db_Adapter_ExceptionTo re-throw PDOException.
See also
Zend_Db_Statement_Exception

Definition at line 221 of file Abstract.php.

222  {
223  if (empty($bind) && $sql instanceof Zend_Db_Select) {
224  $bind = $sql->getBind();
225  }
226 
227  if (is_array($bind)) {
228  foreach ($bind as $name => $value) {
229  if (!is_int($name) && !preg_match('/^:/', $name)) {
230  $newName = ":$name";
231  unset($bind[$name]);
232  $bind[$newName] = $value;
233  }
234  }
235  }
236 
237  try {
238  return parent::query($sql, $bind);
239  } catch (PDOException $e) {
243  #require_once 'Zend/Db/Statement/Exception.php';
244  throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
245  }
246  }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setFetchMode()

setFetchMode (   $mode)

Set the PDO fetch mode.

Todo:
Support FETCH_CLASS and FETCH_INTO.
Parameters
int$modeA PDO fetch mode.
Returns
void
Exceptions
Zend_Db_Adapter_Exception
See also
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception

Definition at line 334 of file Abstract.php.

335  {
336  //check for PDO extension
337  if (!extension_loaded('pdo')) {
341  #require_once 'Zend/Db/Adapter/Exception.php';
342  throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
343  }
344  switch ($mode) {
345  case PDO::FETCH_LAZY:
346  case PDO::FETCH_ASSOC:
347  case PDO::FETCH_NUM:
348  case PDO::FETCH_BOTH:
349  case PDO::FETCH_NAMED:
350  case PDO::FETCH_OBJ:
351  $this->_fetchMode = $mode;
352  break;
353  default:
357  #require_once 'Zend/Db/Adapter/Exception.php';
358  throw new Zend_Db_Adapter_Exception("Invalid fetch mode '$mode' specified");
359  break;
360  }
361  }
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15

◆ supportsParameters()

supportsParameters (   $type)

Check if the adapter supports real SQL parameters.

Parameters
string$type'positional' or 'named'
Returns
bool

Definition at line 369 of file Abstract.php.

370  {
371  switch ($type) {
372  case 'positional':
373  case 'named':
374  default:
375  return true;
376  }
377  }
$type
Definition: item.phtml:13

Field Documentation

◆ $_defaultStmtClass

$_defaultStmtClass = 'Zend_Db_Statement_Pdo'
protected

Definition at line 53 of file Abstract.php.


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