libraries:databaseconnector:databaseconnectorclass:sqlgetnextpreparedlineasobject
DatabaseConnector::SqlGetNextPreparedLineAsObject()
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 object with the next row of the query with columns as attributes that can be accessed via index ($result→2
) or name ($result→name
).
Important! SqlGetFirstPreparedLine() or SqlGetFirstPreparedLineAsObject() has to be called prior to this method.
Object SqlGetNextPreparedLineAsObject ( )
Returns
- Object
Next row of the result of the executed query as object (structure as set in parameter$FetchMode
of SqlPrepareStatement()),NULL
if no further result could be found orFALSE
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->SqlGetFirstPreparedLineAsObject(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->SqlGetNextPreparedLineAsObject(); } while ($Row !== FALSE && $Row !== NULL) }
libraries/databaseconnector/databaseconnectorclass/sqlgetnextpreparedlineasobject.txt · Last modified: 2023/03/03 11:38 by michael.pohl