User Tools

Site Tools


libraries:databaseconnector:databaseconnectorclass:sqlgetnextpreparedline

DatabaseConnector::SqlGetNextPreparedLine()


Definition

Executes a SQL statement that was prepared with SqlPrepareStatement() and replaces the given parameters in their order with the placeholder ('?') in the statement. The result is an array with the next row of the query that can be accessed via index ($result[2]) or name ($result['name']).

Important! SqlGetFirstPreparedLine() or SqlGetFirstPreparedLineAsObject() has to be called prior to this method.

Array SqlGetNextPreparedLine ( )

Returns

  • Array
    Next row of the result of the executed query (structure as set in parameter $FetchMode of SqlPrepareStatement()), NULL if no further result could be found or FALSE if an error occured (see also GetLastError()).

Example

require_once 'DatabaseConnector/DatabaseConnector.php';
 
$DB = new DatabaseConnector();
 
// Connection to a SQLite3 database
$DB->ConnectSQLite3( '/htdocs/data/database1.sqlite3' );
 
// Preparing the statement with two placeholders
$DB->SqlPrepareStatement('SELECT id, username FROM #_users WHERE birthyear BETWEEN ? AND ?');
 
// Requesting user data line by line
$Row = $DB->SqlGetFirstPreparedLine(1970, 2010);
 
if ($Row !== FALSE && $Row !== NULL)
{
   do
   {
      echo 'User ' . $Item['username'] . ' is born in year ' . $Item['birthyear'] . '<br>';
 
      // Fetching the next row
      $Row = $DB->SqlGetNextPreparedLine();
   }
   while ($Row !== FALSE && $Row !== NULL)
}
libraries/databaseconnector/databaseconnectorclass/sqlgetnextpreparedline.txt · Last modified: 2023/03/03 11:36 by michael.pohl