User Tools

Site Tools


libraries:databaseconnector:databaseconnectorclass:sqlgetfirstpreparedlineasobject

DatabaseConnector::SqlGetFirstPreparedLineAsObject()


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 columns as attributes that can be accessed by index ($result→2) or name ($result→name).

Array SqlGetFirstPreparedLine ( [$ParameterArray = NULL] )

Parameters

  • $ParameterArray Array (optional)
    One dimensional array with values to replace the ? placeholders or key-value pairs to replace the :name placeholders

Returns

  • Object
    First Row of the result of the executed query as object (structure as set in parameter $FetchMode of SqlPrepareStatement()), NULL if no 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->SqlGetFirstPreparedLineAsObject( array(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/sqlgetfirstpreparedlineasobject.txt · Last modified: 2023/03/31 19:24 by michael.pohl