User Tools

Site Tools


libraries:databaseconnector:databaseconnectorclass:sqlgetpreparedlines

DatabaseConnector::SqlGetPreparedLines()


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 that can be accessed via index ($result[0][2]) or name ($result[0]['name']).

Array SqlGetPreparedLines ( [$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
    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 ?');
 
// Getting the result with two numeric parameters
$arrResult = $DB->SqlGetPreparedLines( array(1970, 2011) );
 
if ($arrResult  === FALSE )
{
   echo 'Error: ' . $DB->GetLastError();
}
else
{
   foreach ($arrResult AS $Item)
   {
      echo 'User ' . $Item['username'] . ' is born in year ' . $Item['birthyear'] . '<br>';
   }
}
libraries/databaseconnector/databaseconnectorclass/sqlgetpreparedlines.txt · Last modified: 2023/03/31 19:21 by michael.pohl