Child pages
  • [database] PHP Warning, when profiling "kDBConnection::GetColIterator" result [5.2.2-B1]
Skip to end of metadata
Go to start of metadata

The "kDBConnection" class is main way of accessing database in In-Portal. There are 2 main approaches for getting data from database:

  • get all data at once - you'll get array with all data back, but memory for storing that data is allocated upfront
  • get one row at a time - you'll get an iterator back, that will consume memory for storing 1 row only

The iterator approach can be used in 2 ways:

Using "kDBConnector::GetIterator" methodUsing "kDBConnector::GetColIterator" method
$sql = 'SELECT PhraseKey
		FROM ' . TABLE_PREFIX . 'LanguageLabels';
$data = $this->Application->Conn->GetIterator($sql);

Useful, when each row contains several fields.

$sql = 'SELECT PhraseKey
		FROM ' . TABLE_PREFIX . 'LanguageLabels';
$data = $this->Application->Conn->GetColIterator($sql);

Useful, when each row contains one field.

When SELECT result 1 row * 1 column, then Debugger will show that value like so:

Unfortunately, when "kDBConnection::GetColIterator" method is used the result isn't shown and this PHP Warning is triggered:

Warning (#2): current() expects parameter 1 to be array, string given in ...\core\kernel\db\db_connection.php on line 1089


Prior to using "current" function in "kDBConnectionDebug::GetIterator" method make sure, that current row is an array.

Related Tasks

INP-1640 - Getting issue details... STATUS