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_Sqlsrv Class Reference
Inheritance diagram for Zend_Db_Statement_Sqlsrv:
Zend_Db_Statement Zend_Db_Statement_Interface

Public Member Functions

 closeCursor ()
 
 columnCount ()
 
 errorCode ()
 
 errorInfo ()
 
 _execute (array $params=null)
 
 fetch ($style=null, $cursor=null, $offset=null)
 
 fetchColumn ($col=0)
 
 fetchObject ($class='stdClass', array $config=array())
 
 getColumnMeta ($column)
 
 nextRowset ()
 
 rowCount ()
 
 fetchAll ($style=null, $col=null)
 
- 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

 _prepare ($sql)
 
 _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

 $_originalSQL
 
 $_keys
 
 $_executed = false
 
- 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 37 of file Sqlsrv.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_Exception

Definition at line 87 of file Sqlsrv.php.

88  {
89  //Sql server doesn't support bind by name
90  return true;
91  }

◆ _execute()

_execute ( array  $params = null)

Executes a prepared statement.

Parameters
array$paramsOPTIONAL Values to bind to parameter placeholders.
Returns
bool
Exceptions
Zend_Db_Statement_Exception

Definition at line 177 of file Sqlsrv.php.

178  {
179  $connection = $this->_adapter->getConnection();
180  if (!$this->_stmt) {
181  return false;
182  }
183 
184  if ($params !== null) {
185  if (!is_array($params)) {
186  $params = array($params);
187  }
188  $error = false;
189 
190  // make all params passed by reference
191  $params_ = array();
192  $temp = array();
193  $i = 1;
194  foreach ($params as $param) {
195  $temp[$i] = $param;
196  $params_[] = &$temp[$i];
197  $i++;
198  }
199  $params = $params_;
200  }
201 
202  $this->_stmt = sqlsrv_query($connection, $this->_originalSQL, $params);
203 
204  if (!$this->_stmt) {
205  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
206  throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
207  }
208 
209  $this->_executed = true;
210 
211  return (!$this->_stmt);
212  }
$connection
Definition: bulk.php:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$i
Definition: gallery.phtml:31

◆ _prepare()

_prepare (   $sql)
protected

Prepares statement handle

Parameters
string$sql
Returns
void
Exceptions
Zend_Db_Statement_Sqlsrv_Exception

Definition at line 62 of file Sqlsrv.php.

63  {
64  $connection = $this->_adapter->getConnection();
65 
66  $this->_stmt = sqlsrv_prepare($connection, $sql);
67 
68  if (!$this->_stmt) {
69  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
70  throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
71  }
72 
73  $this->_originalSQL = $sql;
74  }
$connection
Definition: bulk.php:13

◆ closeCursor()

closeCursor ( )

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

Returns
bool

Implements Zend_Db_Statement_Interface.

Definition at line 98 of file Sqlsrv.php.

99  {
100  if (!$this->_stmt) {
101  return false;
102  }
103 
104  sqlsrv_free_stmt($this->_stmt);
105  $this->_stmt = false;
106  return true;
107  }

◆ 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 115 of file Sqlsrv.php.

116  {
117  if ($this->_stmt && $this->_executed) {
118  return sqlsrv_num_fields($this->_stmt);
119  }
120 
121  return 0;
122  }

◆ 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 131 of file Sqlsrv.php.

132  {
133  if (!$this->_stmt) {
134  return false;
135  }
136 
137  $error = sqlsrv_errors();
138  if (!$error) {
139  return false;
140  }
141 
142  return $error[0]['code'];
143  }

◆ 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 152 of file Sqlsrv.php.

153  {
154  if (!$this->_stmt) {
155  return false;
156  }
157 
158  $error = sqlsrv_errors();
159  if (!$error) {
160  return false;
161  }
162 
163  return array(
164  $error[0]['code'],
165  $error[0]['message'],
166  );
167  }

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

Implements Zend_Db_Statement_Interface.

Definition at line 223 of file Sqlsrv.php.

224  {
225  if (!$this->_stmt) {
226  return false;
227  }
228 
229  if (null === $style) {
230  $style = $this->_fetchMode;
231  }
232 
233  $values = sqlsrv_fetch_array($this->_stmt, SQLSRV_FETCH_ASSOC);
234 
235  if (!$values && (null !== $error = sqlsrv_errors())) {
236  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
237  throw new Zend_Db_Statement_Sqlsrv_Exception($error);
238  }
239 
240  if (null === $values) {
241  return null;
242  }
243 
244  if (!$this->_keys) {
245  foreach ($values as $key => $value) {
246  $this->_keys[] = $this->_adapter->foldCase($key);
247  }
248  }
249 
250  $values = array_values($values);
251 
252  $row = false;
253  switch ($style) {
254  case Zend_Db::FETCH_NUM:
255  $row = $values;
256  break;
258  $row = array_combine($this->_keys, $values);
259  break;
260  case Zend_Db::FETCH_BOTH:
261  $assoc = array_combine($this->_keys, $values);
262  $row = array_merge($values, $assoc);
263  break;
264  case Zend_Db::FETCH_OBJ:
265  $row = (object) array_combine($this->_keys, $values);
266  break;
268  $assoc = array_combine($this->_keys, $values);
269  $row = array_merge($values, $assoc);
270  $row = $this->_fetchBound($row);
271  break;
272  default:
273  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
274  throw new Zend_Db_Statement_Sqlsrv_Exception("Invalid fetch mode '$style' specified");
275  break;
276  }
277 
278  return $row;
279  }
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
$value
Definition: gender.phtml:16
const FETCH_NUM
Definition: Db.php:153
const FETCH_OBJ
Definition: Db.php:154

◆ fetchAll()

fetchAll (   $style = null,
  $col = null 
)

Returns an array containing all of the result set rows.

Parameters
int$styleOPTIONAL Fetch mode.
int$colOPTIONAL Column number, if fetch mode is by column.
Returns
array Collection of rows, each in a format by the fetch mode.

Behaves like parent, but if limit() is used, the final result removes the extra column 'zend_db_rownum'

Implements Zend_Db_Statement_Interface.

Definition at line 426 of file Sqlsrv.php.

427  {
428  $data = parent::fetchAll($style, $col);
429  $results = array();
430  $remove = $this->_adapter->foldCase('ZEND_DB_ROWNUM');
431 
432  foreach ($data as $row) {
433  if (is_array($row) && array_key_exists($remove, $row)) {
434  unset($row[$remove]);
435  }
436  $results[] = $row;
437  }
438  return $results;
439  }
$results
Definition: popup.phtml:13

◆ fetchColumn()

fetchColumn (   $col = 0)

Returns a single column from the next row of a result set.

Parameters
int$colOPTIONAL Position of the column to fetch.
Returns
string
Exceptions
Zend_Db_Statement_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 288 of file Sqlsrv.php.

289  {
290  if (!$this->_stmt) {
291  return false;
292  }
293 
294  if (!sqlsrv_fetch($this->_stmt)) {
295  if (null !== $error = sqlsrv_errors()) {
296  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
297  throw new Zend_Db_Statement_Sqlsrv_Exception($error);
298  }
299 
300  // If no error, there is simply no record
301  return false;
302  }
303 
304  $data = sqlsrv_get_field($this->_stmt, $col); //0-based
305  if ($data === false) {
306  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
307  throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
308  }
309 
310  return $data;
311  }

◆ fetchObject()

fetchObject (   $class = 'stdClass',
array  $config = array() 
)

Fetches the next row and returns it as an object.

Parameters
string$classOPTIONAL Name of the class to create.
array$configOPTIONAL Constructor arguments for the class.
Returns
mixed One object instance of the specified class.
Exceptions
Zend_Db_Statement_Exception

Implements Zend_Db_Statement_Interface.

Definition at line 321 of file Sqlsrv.php.

322  {
323  if (!$this->_stmt) {
324  return false;
325  }
326 
327  $obj = sqlsrv_fetch_object($this->_stmt);
328 
329  if ($error = sqlsrv_errors()) {
330  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
331  throw new Zend_Db_Statement_Sqlsrv_Exception($error);
332  }
333 
334  /* @todo XXX handle parameters */
335 
336  if (null === $obj) {
337  return false;
338  }
339 
340  return $obj;
341  }

◆ getColumnMeta()

getColumnMeta (   $column)

Returns metadata for a column in a result set.

Parameters
int$column
Returns
mixed
Exceptions
Zend_Db_Statement_Sqlsrv_Exception

Definition at line 350 of file Sqlsrv.php.

351  {
352  $fields = sqlsrv_field_metadata($this->_stmt);
353 
354  if (!$fields) {
355  throw new Zend_Db_Statement_Sqlsrv_Exception('Column metadata can not be fetched');
356  }
357 
358  if (!isset($fields[$column])) {
359  throw new Zend_Db_Statement_Sqlsrv_Exception('Column index does not exist in statement');
360  }
361 
362  return $fields[$column];
363  }
$fields
Definition: details.phtml:14

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

Implements Zend_Db_Statement_Interface.

Definition at line 373 of file Sqlsrv.php.

374  {
375  if (sqlsrv_next_result($this->_stmt) === false) {
376  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
377  throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
378  }
379 
380  // reset column keys
381  $this->_keys = null;
382 
383  return true;
384  }

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

Implements Zend_Db_Statement_Interface.

Definition at line 394 of file Sqlsrv.php.

395  {
396  if (!$this->_stmt) {
397  return false;
398  }
399 
400  if (!$this->_executed) {
401  return 0;
402  }
403 
404  $num_rows = sqlsrv_rows_affected($this->_stmt);
405 
406  // Strict check is necessary; 0 is a valid return value
407  if ($num_rows === false) {
408  #require_once 'Zend/Db/Statement/Sqlsrv/Exception.php';
409  throw new Zend_Db_Statement_Sqlsrv_Exception(sqlsrv_errors());
410  }
411 
412  return $num_rows;
413  }

Field Documentation

◆ $_executed

$_executed = false
protected

Query executed

Definition at line 53 of file Sqlsrv.php.

◆ $_keys

$_keys
protected

Column names.

Definition at line 48 of file Sqlsrv.php.

◆ $_originalSQL

$_originalSQL
protected

The connection_stmt object original string.

Definition at line 43 of file Sqlsrv.php.


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