Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Db_Statement_Mysqli Class Reference
Inheritance diagram for Zend_Db_Statement_Mysqli:
Zend_Db_Statement Zend_Db_Statement_Interface

Public Member Functions

 _prepare ($sql)
 
 close ()
 
 closeCursor ()
 
 columnCount ()
 
 errorCode ()
 
 errorInfo ()
 
 _execute (array $params=null)
 
 fetch ($style=null, $cursor=null, $offset=null)
 
 nextRowset ()
 
 rowCount ()
 
- Public Member Functions inherited from Zend_Db_Statement
 __construct ($adapter, $sql)
 
 bindColumn ($column, &$param, $type=null)
 
 bindParam ($parameter, &$variable, $type=null, $length=null, $options=null)
 
 bindValue ($parameter, $value, $type=null)
 
 execute (array $params=null)
 
 fetchAll ($style=null, $col=null)
 
 fetchColumn ($col=0)
 
 fetchObject ($class='stdClass', array $config=array())
 
 getAttribute ($key)
 
 setAttribute ($key, $val)
 
 setFetchMode ($mode)
 
 _fetchBound ($row)
 
 getAdapter ()
 
 getDriverStatement ()
 

Protected Member Functions

 _bindParam ($parameter, &$variable, $type=null, $length=null, $options=null)
 
- Protected Member Functions inherited from Zend_Db_Statement
 _prepare ($sql)
 
 _parseParameters ($sql)
 
 _stripQuoted ($sql)
 

Protected Attributes

 $_keys
 
 $_values
 
 $_meta = null
 
- Protected Attributes inherited from Zend_Db_Statement
 $_stmt = null
 
 $_adapter = null
 
 $_fetchMode = Zend_Db::FETCH_ASSOC
 
 $_attribute = array()
 
 $_bindColumn = array()
 
 $_bindParam = array()
 
 $_sqlSplit = array()
 
 $_sqlParam = array()
 
 $_queryId = null
 

Detailed Description

Definition at line 39 of file Mysqli.php.

Member Function Documentation

◆ _bindParam()

_bindParam (   $parameter,
$variable,
  $type = null,
  $length = null,
  $options = null 
)
protected

Binds a parameter to the specified variable name.

Parameters
mixed$parameterName the parameter, either integer or string.
mixed$variableReference to PHP variable containing the value.
mixed$typeOPTIONAL Datatype of SQL parameter.
mixed$lengthOPTIONAL Length of SQL parameter.
mixed$optionsOPTIONAL Other options.
Returns
bool
Exceptions
Zend_Db_Statement_Mysqli_Exception

Definition at line 92 of file Mysqli.php.

93  {
94  return true;
95  }

◆ _execute()

_execute ( array  $params = null)

Executes a prepared statement.

Parameters
array$paramsOPTIONAL Values to bind to parameter placeholders.
Returns
bool
Exceptions
Zend_Db_Statement_Mysqli_Exception
See also
Zend_Db_Statement_Mysqli_Exception
Zend_Db_Statement_Mysqli_Exception

Definition at line 183 of file Mysqli.php.

184  {
185  if (!$this->_stmt) {
186  return false;
187  }
188 
189  // if no params were given as an argument to execute(),
190  // then default to the _bindParam array
191  if ($params === null) {
193  }
194  // send $params as input parameters to the statement
195  if ($params) {
196  array_unshift($params, str_repeat('s', count($params)));
197  $stmtParams = array();
198  foreach ($params as $k => &$value) {
199  $stmtParams[$k] = &$value;
200  }
201  call_user_func_array(
202  array($this->_stmt, 'bind_param'),
203  $stmtParams
204  );
205  }
206 
207  // execute the statement
208  $retval = $this->_stmt->execute();
209  if ($retval === false) {
213  #require_once 'Zend/Db/Statement/Mysqli/Exception.php';
214  throw new Zend_Db_Statement_Mysqli_Exception("Mysqli statement execute error : " . $this->_stmt->error, $this->_stmt->errno);
215  }
216 
217 
218  // retain metadata
219  if ($this->_meta === null) {
220  $this->_meta = $this->_stmt->result_metadata();
221  if ($this->_stmt->errno) {
225  #require_once 'Zend/Db/Statement/Mysqli/Exception.php';
226  throw new Zend_Db_Statement_Mysqli_Exception("Mysqli statement metadata error: " . $this->_stmt->error, $this->_stmt->errno);
227  }
228  }
229 
230  // statements that have no result set do not return metadata
231  if ($this->_meta !== false) {
232 
233  // get the column names that will result
234  $this->_keys = array();
235  foreach ($this->_meta->fetch_fields() as $col) {
236  $this->_keys[] = $this->_adapter->foldCase($col->name);
237  }
238 
239  // set up a binding space for result variables
240  $this->_values = array_fill(0, count($this->_keys), null);
241 
242  // set up references to the result binding space.
243  // just passing $this->_values in the call_user_func_array()
244  // below won't work, you need references.
245  $refs = array();
246  foreach ($this->_values as $i => &$f) {
247  $refs[$i] = &$f;
248  }
249 
250  $this->_stmt->store_result();
251  // bind to the result variables
252  call_user_func_array(
253  array($this->_stmt, 'bind_result'),
254  $this->_values
255  );
256  }
257  return $retval;
258  }
$value
Definition: gender.phtml:16
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$i
Definition: gallery.phtml:31

◆ _prepare()

_prepare (   $sql)
Parameters
string$sql
Returns
void
Exceptions
Zend_Db_Statement_Mysqli_Exception
See also
Zend_Db_Statement_Mysqli_Exception

Definition at line 66 of file Mysqli.php.

67  {
68  $mysqli = $this->_adapter->getConnection();
69 
70  $this->_stmt = $mysqli->prepare($sql);
71 
72  if ($this->_stmt === false || $mysqli->errno) {
76  #require_once 'Zend/Db/Statement/Mysqli/Exception.php';
77  throw new Zend_Db_Statement_Mysqli_Exception("Mysqli prepare error: " . $mysqli->error, $mysqli->errno);
78  }
79  }

◆ close()

close ( )

Closes the cursor and the statement.

Returns
bool

Definition at line 102 of file Mysqli.php.

103  {
104  if ($this->_stmt) {
105  $r = $this->_stmt->close();
106  $this->_stmt = null;
107  return $r;
108  }
109  return false;
110  }

◆ closeCursor()

closeCursor ( )

Closes the cursor, allowing the statement to be executed again.

Returns
bool

Implements Zend_Db_Statement_Interface.

Definition at line 117 of file Mysqli.php.

118  {
119  if ($stmt = $this->_stmt) {
120  $mysqli = $this->_adapter->getConnection();
121  while ($mysqli->more_results()) {
122  $mysqli->next_result();
123  }
124  $this->_stmt->free_result();
125  return $this->_stmt->reset();
126  }
127  return false;
128  }

◆ columnCount()

columnCount ( )

Returns the number of columns in the result set. Returns null if the statement has no result set metadata.

Returns
int The number of columns.

Implements Zend_Db_Statement_Interface.

Definition at line 136 of file Mysqli.php.

137  {
138  if (isset($this->_meta) && $this->_meta) {
139  return $this->_meta->field_count;
140  }
141  return 0;
142  }

◆ errorCode()

errorCode ( )

Retrieves the error code, if any, associated with the last operation on the statement handle.

Returns
string error code.

Implements Zend_Db_Statement_Interface.

Definition at line 150 of file Mysqli.php.

151  {
152  if (!$this->_stmt) {
153  return false;
154  }
155  return substr($this->_stmt->sqlstate, 0, 5);
156  }

◆ errorInfo()

errorInfo ( )

Retrieves an array of error information, if any, associated with the last operation on the statement handle.

Returns
array

Implements Zend_Db_Statement_Interface.

Definition at line 164 of file Mysqli.php.

165  {
166  if (!$this->_stmt) {
167  return false;
168  }
169  return array(
170  substr($this->_stmt->sqlstate, 0, 5),
171  $this->_stmt->errno,
172  $this->_stmt->error,
173  );
174  }

◆ fetch()

fetch (   $style = null,
  $cursor = null,
  $offset = null 
)

Fetches a row from the result set.

Parameters
int$styleOPTIONAL Fetch mode for this fetch operation.
int$cursorOPTIONAL Absolute, relative, or other.
int$offsetOPTIONAL Number for absolute or relative cursors.
Returns
mixed Array, object, or scalar depending on fetch mode.
Exceptions
Zend_Db_Statement_Mysqli_Exception
See also
Zend_Db_Statement_Mysqli_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 270 of file Mysqli.php.

271  {
272  if (!$this->_stmt) {
273  return false;
274  }
275  // fetch the next result
276  $retval = $this->_stmt->fetch();
277  switch ($retval) {
278  case null: // end of data
279  case false: // error occurred
280  $this->_stmt->reset();
281  return false;
282  default:
283  // fallthrough
284  }
285 
286  // make sure we have a fetch mode
287  if ($style === null) {
288  $style = $this->_fetchMode;
289  }
290 
291  // dereference the result values, otherwise things like fetchAll()
292  // return the same values for every entry (because of the reference).
293  $values = array();
294  foreach ($this->_values as $key => $val) {
295  $values[] = $val;
296  }
297 
298  $row = false;
299  switch ($style) {
300  case Zend_Db::FETCH_NUM:
301  $row = $values;
302  break;
304  $row = array_combine($this->_keys, $values);
305  break;
306  case Zend_Db::FETCH_BOTH:
307  $assoc = array_combine($this->_keys, $values);
308  $row = array_merge($values, $assoc);
309  break;
310  case Zend_Db::FETCH_OBJ:
311  $row = (object) array_combine($this->_keys, $values);
312  break;
314  $assoc = array_combine($this->_keys, $values);
315  $row = array_merge($values, $assoc);
316  return $this->_fetchBound($row);
317  break;
318  default:
322  #require_once 'Zend/Db/Statement/Mysqli/Exception.php';
323  throw new Zend_Db_Statement_Mysqli_Exception("Invalid fetch mode '$style' specified");
324  break;
325  }
326  return $row;
327  }
const FETCH_BOUND
Definition: Db.php:144
const FETCH_ASSOC
Definition: Db.php:142
$values
Definition: options.phtml:88
const FETCH_BOTH
Definition: Db.php:143
const FETCH_NUM
Definition: Db.php:153
const FETCH_OBJ
Definition: Db.php:154

◆ nextRowset()

nextRowset ( )

Retrieves the next rowset (result set) for a SQL statement that has multiple result sets. An example is a stored procedure that returns the results of multiple queries.

Returns
bool
Exceptions
Zend_Db_Statement_Mysqli_Exception
See also
Zend_Db_Statement_Mysqli_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 337 of file Mysqli.php.

338  {
342  #require_once 'Zend/Db/Statement/Mysqli/Exception.php';
343  throw new Zend_Db_Statement_Mysqli_Exception(__FUNCTION__.'() is not implemented');
344  }

◆ rowCount()

rowCount ( )

Returns the number of rows affected by the execution of the last INSERT, DELETE, or UPDATE statement executed by this statement object.

Returns
int The number of rows affected.

Implements Zend_Db_Statement_Interface.

Definition at line 353 of file Mysqli.php.

354  {
355  if (!$this->_adapter) {
356  return false;
357  }
358  $mysqli = $this->_adapter->getConnection();
359  return $mysqli->affected_rows;
360  }

Field Documentation

◆ $_keys

$_keys
protected

Definition at line 47 of file Mysqli.php.

◆ $_meta

$_meta = null
protected

Definition at line 59 of file Mysqli.php.

◆ $_values

$_values
protected

Definition at line 54 of file Mysqli.php.


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