User Tools

Site Tools


libraries:databaseconnector:databaseconnectorclass:sqlexecuteprepared

DatabaseConnector::SqlExecutePrepared()


Definition

Executes a prepared SQL statement on the connected database without expecting a return value (e.g. UPDATE-Statements).
Important! SqlPrepareStatement() has to be called prior to this method.

Bool SqlExecutePrepared ( [$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

  • Bool
    TRUE if the query was successful or FALSE on failure. (see also GetLastError()).

Example

require_once 'DatabaseConnector/DatabaseConnector.php';
 
$DB = new DatabaseConnector();
 
// Connection to a SQLite3 database
$DB->ConnectSQLite3( '/htdocs/data/database1.sqlite3' );
 
// 1st option:
// Preparing the statement with named placeholders
$DB->SqlPrepareStatement('UPDATE tbl_user SET name = :name WHERE id = :id');
 
// Executing the query with two dimensional array
$bResult = $DB->SqlExecutePrepared( array('name' => 'John Doe', 'id' => 5) );
 
// 2nd option:
// Preparing the statement with unnamed placeholders
$DB->SqlPrepareStatement('UPDATE tbl_user SET name = ? WHERE id = ?');
 
// Executing the query with one dimensional array
$bResult = $DB->SqlExecutePrepared( array('John Doe', 5) );
 
 
if ($arrResult  === FALSE )
{
   echo 'Error: ' . $DB->GetLastError();
}
else
{
   echo 'Execution successful';
}
libraries/databaseconnector/databaseconnectorclass/sqlexecuteprepared.txt · Last modified: 2023/03/31 19:19 by michael.pohl