User Tools

Site Tools


libraries:databaseconnector:databaseconnectorclass:sqlgetfirstpreparedline

DatabaseConnector::SqlGetFirstPreparedLine()


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 first row of the query that can be accessed via 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

  • Array
    First Row of the result of the executed query (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->SqlGetFirstPreparedLine( 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->SqlGetNextPreparedLine();
   }
   while ($Row !== FALSE && $Row !== NULL)
}
libraries/databaseconnector/databaseconnectorclass/sqlgetfirstpreparedline.txt · Last modified: 2023/03/31 19:23 by michael.pohl