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_Mysqli Class Reference
Inheritance diagram for Zend_Db_Adapter_Mysqli:
Zend_Db_Adapter_Abstract

Public Member Functions

 getQuoteIdentifierSymbol ()
 
 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 isConnected ()
 
 closeConnection ()
 
 prepare ($sql)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
 setFetchMode ($mode)
 
 limit ($sql, $count, $offset=0)
 
 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

 _quote ($value)
 
 _connect ()
 
 _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

 $_numericDataTypes
 
 $_stmt = null
 
 $_defaultStmtClass = 'Zend_Db_Statement_Mysqli'
 
- 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 52 of file Mysqli.php.

Member Function Documentation

◆ _beginTransaction()

_beginTransaction ( )
protected

Begin a transaction.

Returns
void

Definition at line 425 of file Mysqli.php.

426  {
427  $this->_connect();
428  $this->_connection->autocommit(false);
429  }

◆ _commit()

_commit ( )
protected

Commit a transaction.

Returns
void

Definition at line 436 of file Mysqli.php.

437  {
438  $this->_connect();
439  $this->_connection->commit();
440  $this->_connection->autocommit(true);
441  }

◆ _connect()

_connect ( )
protected

Creates a connection to the database.

Returns
void
Exceptions
Zend_Db_Adapter_Mysqli_Exception
See also
Zend_Db_Adapter_Mysqli_Exception
Zend_Db_Adapter_Mysqli_Exception

Definition at line 280 of file Mysqli.php.

281  {
282  if ($this->_connection) {
283  return;
284  }
285 
286  if (!extension_loaded('mysqli')) {
290  #require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
291  throw new Zend_Db_Adapter_Mysqli_Exception('The Mysqli extension is required for this adapter but the extension is not loaded');
292  }
293 
294  if (isset($this->_config['port'])) {
295  $port = (integer) $this->_config['port'];
296  } else {
297  $port = null;
298  }
299 
300  if (isset($this->_config['socket'])) {
301  $socket = $this->_config['socket'];
302  } else {
303  $socket = null;
304  }
305 
306  $this->_connection = mysqli_init();
307 
308  if(!empty($this->_config['driver_options'])) {
309  foreach($this->_config['driver_options'] as $option=>$value) {
310  if(is_string($option)) {
311  // Suppress warnings here
312  // Ignore it if it's not a valid constant
313  $option = @constant(strtoupper($option));
314  if($option === null)
315  continue;
316  }
317  mysqli_options($this->_connection, $option, $value);
318  }
319  }
320 
321  // Suppress connection warnings here.
322  // Throw an exception instead.
323  $_isConnected = @mysqli_real_connect(
324  $this->_connection,
325  $this->_config['host'],
326  $this->_config['username'],
327  $this->_config['password'],
328  $this->_config['dbname'],
329  $port,
330  $socket
331  );
332 
333  if ($_isConnected === false || mysqli_connect_errno()) {
334 
335  $this->closeConnection();
339  #require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
340  throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error());
341  }
342 
343  if (!empty($this->_config['charset'])) {
344  mysqli_set_charset($this->_connection, $this->_config['charset']);
345  }
346  }
$value
Definition: gender.phtml:16

◆ _quote()

_quote (   $value)
protected

Quote a raw string.

Parameters
mixed$valueRaw string
Returns
string Quoted string

Definition at line 104 of file Mysqli.php.

105  {
106  if (is_int($value) || is_float($value)) {
107  return $value;
108  }
109  $this->_connect();
110  return "'" . $this->_connection->real_escape_string($value) . "'";
111  }
$value
Definition: gender.phtml:16

◆ _rollBack()

_rollBack ( )
protected

Roll-back a transaction.

Returns
void

Definition at line 448 of file Mysqli.php.

449  {
450  $this->_connect();
451  $this->_connection->rollback();
452  $this->_connection->autocommit(true);
453  }

◆ closeConnection()

closeConnection ( )

Force the connection to close.

Returns
void

Definition at line 363 of file Mysqli.php.

364  {
365  if ($this->isConnected()) {
366  $this->_connection->close();
367  }
368  $this->_connection = null;
369  }

◆ 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
Todo:
use INFORMATION_SCHEMA someday when MySQL's implementation isn't too slow.

Use mysqli extension API, because DESCRIBE doesn't work well as a prepared statement on MySQL 4.1.

See also
Zend_Db_Adapter_Mysqli_Exception

The optional argument of a MySQL int type is not precision or length; it is only a hint for display width.

Definition at line 177 of file Mysqli.php.

178  {
184  if ($schemaName) {
185  $sql = 'DESCRIBE ' . $this->quoteIdentifier("$schemaName.$tableName", true);
186  } else {
187  $sql = 'DESCRIBE ' . $this->quoteIdentifier($tableName, true);
188  }
189 
194  if ($queryResult = $this->getConnection()->query($sql)) {
195  while ($row = $queryResult->fetch_assoc()) {
196  $result[] = $row;
197  }
198  $queryResult->close();
199  } else {
203  #require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
204  throw new Zend_Db_Adapter_Mysqli_Exception($this->getConnection()->error);
205  }
206 
207  $desc = array();
208 
209  $row_defaults = array(
210  'Length' => null,
211  'Scale' => null,
212  'Precision' => null,
213  'Unsigned' => null,
214  'Primary' => false,
215  'PrimaryPosition' => null,
216  'Identity' => false
217  );
218  $i = 1;
219  $p = 1;
220  foreach ($result as $key => $row) {
221  $row = array_merge($row_defaults, $row);
222  if (preg_match('/unsigned/', $row['Type'])) {
223  $row['Unsigned'] = true;
224  }
225  if (preg_match('/^((?:var)?char)\((\d+)\)/', $row['Type'], $matches)) {
226  $row['Type'] = $matches[1];
227  $row['Length'] = $matches[2];
228  } else if (preg_match('/^decimal\((\d+),(\d+)\)/', $row['Type'], $matches)) {
229  $row['Type'] = 'decimal';
230  $row['Precision'] = $matches[1];
231  $row['Scale'] = $matches[2];
232  } else if (preg_match('/^float\((\d+),(\d+)\)/', $row['Type'], $matches)) {
233  $row['Type'] = 'float';
234  $row['Precision'] = $matches[1];
235  $row['Scale'] = $matches[2];
236  } else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row['Type'], $matches)) {
237  $row['Type'] = $matches[1];
242  }
243  if (strtoupper($row['Key']) == 'PRI') {
244  $row['Primary'] = true;
245  $row['PrimaryPosition'] = $p;
246  if ($row['Extra'] == 'auto_increment') {
247  $row['Identity'] = true;
248  } else {
249  $row['Identity'] = false;
250  }
251  ++$p;
252  }
253  $desc[$this->foldCase($row['Field'])] = array(
254  'SCHEMA_NAME' => null, // @todo
255  'TABLE_NAME' => $this->foldCase($tableName),
256  'COLUMN_NAME' => $this->foldCase($row['Field']),
257  'COLUMN_POSITION' => $i,
258  'DATA_TYPE' => $row['Type'],
259  'DEFAULT' => $row['Default'],
260  'NULLABLE' => (bool) ($row['Null'] == 'YES'),
261  'LENGTH' => $row['Length'],
262  'SCALE' => $row['Scale'],
263  'PRECISION' => $row['Precision'],
264  'UNSIGNED' => $row['Unsigned'],
265  'PRIMARY' => $row['Primary'],
266  'PRIMARY_POSITION' => $row['PrimaryPosition'],
267  'IDENTITY' => $row['Identity']
268  );
269  ++$i;
270  }
271  return $desc;
272  }
$tableName
Definition: trigger.php:13
query($sql, $bind=array())
Definition: Abstract.php:457
quoteIdentifier($ident, $auto=false)
Definition: Abstract.php:959
$i
Definition: gallery.phtml:31

◆ getQuoteIdentifierSymbol()

getQuoteIdentifierSymbol ( )

Returns the symbol the adapter uses for delimiting identifiers.

Returns
string

Definition at line 118 of file Mysqli.php.

119  {
120  return "`";
121  }

◆ getServerVersion()

getServerVersion ( )

Retrieve server version in PHP style

Returns
string

Definition at line 547 of file Mysqli.php.

548  {
549  $this->_connect();
550  $version = $this->_connection->server_version;
551  $major = (int) ($version / 10000);
552  $minor = (int) ($version % 10000 / 100);
553  $revision = (int) ($version % 100);
554  return $major . '.' . $minor . '.' . $revision;
555  }

◆ isConnected()

isConnected ( )

Test if a connection is active

Returns
boolean

Definition at line 353 of file Mysqli.php.

354  {
355  return ((bool) ($this->_connection instanceof mysqli));
356  }

◆ 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.

MySQL does not support sequences, so $tableName and $primaryKey are ignored.

Parameters
string$tableNameOPTIONAL Name of table.
string$primaryKeyOPTIONAL Name of primary key column.
Returns
string
Todo:
Return value should be int?

Definition at line 414 of file Mysqli.php.

415  {
416  $mysqli = $this->_connection;
417  return (string) $mysqli->insert_id;
418  }

◆ limit()

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

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

Parameters
string$sql
int$count
int$offsetOPTIONAL
Returns
string
See also
Zend_Db_Adapter_Mysqli_Exception
Zend_Db_Adapter_Mysqli_Exception

Definition at line 497 of file Mysqli.php.

498  {
499  $count = intval($count);
500  if ($count <= 0) {
504  #require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
505  throw new Zend_Db_Adapter_Mysqli_Exception("LIMIT argument count=$count is not valid");
506  }
507 
508  $offset = intval($offset);
509  if ($offset < 0) {
513  #require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
514  throw new Zend_Db_Adapter_Mysqli_Exception("LIMIT argument offset=$offset is not valid");
515  }
516 
517  $sql .= " LIMIT $count";
518  if ($offset > 0) {
519  $sql .= " OFFSET $offset";
520  }
521 
522  return $sql;
523  }
$count
Definition: recent.phtml:13

◆ listTables()

listTables ( )

Returns a list of the tables in the database.

Returns
array
See also
Zend_Db_Adapter_Mysqli_Exception

Definition at line 128 of file Mysqli.php.

129  {
130  $result = array();
131  // Use mysqli extension API, because SHOW doesn't work
132  // well as a prepared statement on MySQL 4.1.
133  $sql = 'SHOW TABLES';
134  if ($queryResult = $this->getConnection()->query($sql)) {
135  while ($row = $queryResult->fetch_row()) {
136  $result[] = $row[0];
137  }
138  $queryResult->close();
139  } else {
143  #require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
144  throw new Zend_Db_Adapter_Mysqli_Exception($this->getConnection()->error);
145  }
146  return $result;
147  }
query($sql, $bind=array())
Definition: Abstract.php:457

◆ prepare()

prepare (   $sql)

Prepare a statement and return a PDOStatement-like object.

Parameters
string$sqlSQL query
Returns
Zend_Db_Statement_Mysqli

Definition at line 377 of file Mysqli.php.

378  {
379  $this->_connect();
380  if ($this->_stmt) {
381  $this->_stmt->close();
382  }
383  $stmtClass = $this->_defaultStmtClass;
384  if (!class_exists($stmtClass)) {
385  #require_once 'Zend/Loader.php';
386  Zend_Loader::loadClass($stmtClass);
387  }
388  $stmt = new $stmtClass($this, $sql);
389  if ($stmt === false) {
390  return false;
391  }
392  $stmt->setFetchMode($this->_fetchMode);
393  $this->_stmt = $stmt;
394  return $stmt;
395  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52

◆ setFetchMode()

setFetchMode (   $mode)

Set the fetch mode.

Parameters
int$mode
Returns
void
Exceptions
Zend_Db_Adapter_Mysqli_Exception
See also
Zend_Db_Adapter_Mysqli_Exception
Zend_Db_Adapter_Mysqli_Exception

Definition at line 462 of file Mysqli.php.

463  {
464  switch ($mode) {
465  case Zend_Db::FETCH_LAZY:
467  case Zend_Db::FETCH_NUM:
468  case Zend_Db::FETCH_BOTH:
470  case Zend_Db::FETCH_OBJ:
471  $this->_fetchMode = $mode;
472  break;
473  case Zend_Db::FETCH_BOUND: // bound to PHP variable
477  #require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
478  throw new Zend_Db_Adapter_Mysqli_Exception('FETCH_BOUND is not supported yet');
479  break;
480  default:
484  #require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
485  throw new Zend_Db_Adapter_Mysqli_Exception("Invalid fetch mode '$mode' specified");
486  }
487  }
const FETCH_LAZY
Definition: Db.php:151
const FETCH_BOUND
Definition: Db.php:144
const FETCH_ASSOC
Definition: Db.php:142
const FETCH_NAMED
Definition: Db.php:152
const FETCH_BOTH
Definition: Db.php:143
const FETCH_NUM
Definition: Db.php:153
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
const FETCH_OBJ
Definition: Db.php:154

◆ supportsParameters()

supportsParameters (   $type)

Check if the adapter supports real SQL parameters.

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

Definition at line 531 of file Mysqli.php.

532  {
533  switch ($type) {
534  case 'positional':
535  return true;
536  case 'named':
537  default:
538  return false;
539  }
540  }
$type
Definition: item.phtml:13

Field Documentation

◆ $_defaultStmtClass

$_defaultStmtClass = 'Zend_Db_Statement_Mysqli'
protected

Definition at line 95 of file Mysqli.php.

◆ $_numericDataTypes

$_numericDataTypes
protected
Initial value:

Definition at line 66 of file Mysqli.php.

◆ $_stmt

$_stmt = null
protected

Definition at line 88 of file Mysqli.php.


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