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_Mysql Class Reference
Inheritance diagram for Zend_Db_Adapter_Pdo_Mysql:
Zend_Db_Adapter_Pdo_Abstract Zend_Db_Adapter_Abstract Mysql Mysql

Public Member Functions

 getQuoteIdentifierSymbol ()
 
 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 limit ($sql, $count, $offset=0)
 
- Public Member Functions inherited from Zend_Db_Adapter_Pdo_Abstract
 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 ()
 
- Protected Member Functions inherited from Zend_Db_Adapter_Pdo_Abstract
 _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

 $_pdoType = 'mysql'
 
 $_numericDataTypes
 
- Protected Attributes inherited from Zend_Db_Adapter_Pdo_Abstract
 $_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 39 of file Mysql.php.

Member Function Documentation

◆ _connect()

_connect ( )
protected

Creates a PDO object and connects to the database.

Returns
void
Exceptions
Zend_Db_Adapter_Exception

Definition at line 98 of file Mysql.php.

99  {
100  if ($this->_connection) {
101  return;
102  }
103 
104  if (!empty($this->_config['charset'])
105  && version_compare(PHP_VERSION, '5.3.6', '<')
106  ) {
107  $initCommand = "SET NAMES '" . $this->_config['charset'] . "'";
108  $this->_config['driver_options'][1002] = $initCommand; // 1002 = PDO::MYSQL_ATTR_INIT_COMMAND
109  }
110 
111  parent::_connect();
112  }

◆ _dsn()

_dsn ( )
protected

Override _dsn() and ensure that charset is incorporated in mysql

See also
Zend_Db_Adapter_Pdo_Abstract::_dsn()

Definition at line 83 of file Mysql.php.

84  {
85  $dsn = parent::_dsn();
86  if (isset($this->_config['charset'])) {
87  $dsn .= ';charset=' . $this->_config['charset'];
88  }
89  return $dsn;
90  }

◆ describeTable()

describeTable (   $tableName,
  $schemaName = null 
)

Returns the column descriptions for a table.

The return value is an associative array keyed by the column name, as returned by the RDBMS.

The value of each array element is an associative array with the following keys:

SCHEMA_NAME => string; name of database or schema TABLE_NAME => string; COLUMN_NAME => string; column name COLUMN_POSITION => number; ordinal position of column in table DATA_TYPE => string; SQL datatype name of column DEFAULT => string; default expression of column, null if none NULLABLE => boolean; true if column can have nulls LENGTH => number; length of CHAR/VARCHAR SCALE => number; scale of NUMERIC/DECIMAL PRECISION => number; precision of NUMERIC/DECIMAL UNSIGNED => boolean; unsigned property of an integer type PRIMARY => boolean; true if column is part of the primary key PRIMARY_POSITION => integer; position of column in primary key IDENTITY => integer; true if column is auto-generated with unique values

Parameters
string$tableName
string$schemaNameOPTIONAL
Returns
array

Definition at line 160 of file Mysql.php.

161  {
162  // @todo use INFORMATION_SCHEMA someday when MySQL's
163  // implementation has reasonably good performance and
164  // the version with this improvement is in wide use.
165 
166  if ($schemaName) {
167  $sql = 'DESCRIBE ' . $this->quoteIdentifier("$schemaName.$tableName", true);
168  } else {
169  $sql = 'DESCRIBE ' . $this->quoteIdentifier($tableName, true);
170  }
171  $stmt = $this->query($sql);
172 
173  // Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
174  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
175 
176  $field = 0;
177  $type = 1;
178  $null = 2;
179  $key = 3;
180  $default = 4;
181  $extra = 5;
182 
183  $desc = array();
184  $i = 1;
185  $p = 1;
186  foreach ($result as $row) {
187  list($length, $scale, $precision, $unsigned, $primary, $primaryPosition, $identity)
188  = array(null, null, null, null, false, null, false);
189  if (preg_match('/unsigned/', $row[$type])) {
190  $unsigned = true;
191  }
192  if (preg_match('/^((?:var)?char)\((\d+)\)/', $row[$type], $matches)) {
193  $row[$type] = $matches[1];
194  $length = $matches[2];
195  } else if (preg_match('/^decimal\((\d+),(\d+)\)/', $row[$type], $matches)) {
196  $row[$type] = 'decimal';
197  $precision = $matches[1];
198  $scale = $matches[2];
199  } else if (preg_match('/^float\((\d+),(\d+)\)/', $row[$type], $matches)) {
200  $row[$type] = 'float';
201  $precision = $matches[1];
202  $scale = $matches[2];
203  } else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row[$type], $matches)) {
204  $row[$type] = $matches[1];
205  // The optional argument of a MySQL int type is not precision
206  // or length; it is only a hint for display width.
207  }
208  if (strtoupper($row[$key]) == 'PRI') {
209  $primary = true;
210  $primaryPosition = $p;
211  if ($row[$extra] == 'auto_increment') {
212  $identity = true;
213  } else {
214  $identity = false;
215  }
216  ++$p;
217  }
218  $desc[$this->foldCase($row[$field])] = array(
219  'SCHEMA_NAME' => null, // @todo
220  'TABLE_NAME' => $this->foldCase($tableName),
221  'COLUMN_NAME' => $this->foldCase($row[$field]),
222  'COLUMN_POSITION' => $i,
223  'DATA_TYPE' => $row[$type],
224  'DEFAULT' => $row[$default],
225  'NULLABLE' => (bool) ($row[$null] == 'YES'),
226  'LENGTH' => $length,
227  'SCALE' => $scale,
228  'PRECISION' => $precision,
229  'UNSIGNED' => $unsigned,
230  'PRIMARY' => $primary,
231  'PRIMARY_POSITION' => $primaryPosition,
232  'IDENTITY' => $identity
233  );
234  ++$i;
235  }
236  return $desc;
237  }
$tableName
Definition: trigger.php:13
$type
Definition: item.phtml:13
const FETCH_NUM
Definition: Db.php:153
quoteIdentifier($ident, $auto=false)
Definition: Abstract.php:959
$i
Definition: gallery.phtml:31
query($sql, $bind=array())
Definition: Abstract.php:221
if( $_orders &&count( $_orders))( 'Orders') ?></caption >< thead >< tr >< th scopeforeach( $_orders as $_order)(__( 'Order #')) ?>" class $extra
Definition: history.phtml:32

◆ getQuoteIdentifierSymbol()

getQuoteIdentifierSymbol ( )
Returns
string

Definition at line 117 of file Mysql.php.

118  {
119  return "`";
120  }

◆ limit()

limit (   $sql,
  $count,
  $offset = 0 
)

Adds an adapter-specific LIMIT clause to the SELECT statement.

Parameters
string$sql
integer$count
integer$offsetOPTIONAL
Exceptions
Zend_Db_Adapter_Exception
Returns
string
See also
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception

Definition at line 248 of file Mysql.php.

249  {
250  $count = intval($count);
251  if ($count <= 0) {
253  #require_once 'Zend/Db/Adapter/Exception.php';
254  throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
255  }
256 
257  $offset = intval($offset);
258  if ($offset < 0) {
260  #require_once 'Zend/Db/Adapter/Exception.php';
261  throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
262  }
263 
264  $sql .= " LIMIT $count";
265  if ($offset > 0) {
266  $sql .= " OFFSET $offset";
267  }
268 
269  return $sql;
270  }
$count
Definition: recent.phtml:13

◆ listTables()

listTables ( )

Returns a list of the tables in the database.

Returns
array

Definition at line 127 of file Mysql.php.

128  {
129  return $this->fetchCol('SHOW TABLES');
130  }
fetchCol($sql, $bind=array())
Definition: Abstract.php:792

Field Documentation

◆ $_numericDataTypes

$_numericDataTypes
protected
Initial value:

Definition at line 60 of file Mysql.php.

◆ $_pdoType

$_pdoType = 'mysql'
protected

Definition at line 47 of file Mysql.php.


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