SDO_DAS_Relational::executePreparedQueryExecutes an SQL query passed as a prepared statement, with a list of values to substitute for placeholders, and return the results as a normalised data graph. Description
SDODataObject
SDO_DAS_Relational::executePreparedQuery
(
PDO
$database_handle
,
PDOStatement
$prepared_statement
,
array
$value_list
[,
array
$column_specifier
] )Warning
This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk. Executes a given query against the relational database, using the supplied PDO database handle. Differs from the simpler executeQuery in that it takes a prepared statement and a list of values. This is the appropriate call to use either when the statement is to executed a number of times with different arguments, and there is therefore a performance benefit to be had from preparing the statement only once, or when the SQL statement is to contain varying values taken from a source that cannot be completely trusted. In this latter case it may be unsafe to construct the SQL statement by simply concatenating the parts of the statement together, since the values may contain pieces of SQL. To guard against this, a so-called SQL injection attack, it is safer to prepare the SQL statement with placeholders (also known as parameter markers, denoted by '?') and supply a list of the values to be substituted as a separate argument. Otherwise this function is the same as executeQuery in that it uses the model that it built from the metadata to interpret the result set and returns a data graph. Parameters
Return ValuesReturns a data graph. Specifically, it returns a root object of a special type. Under this root object will be the data from the result set. The root object will have a multi-valued containment property with the same name as the application root type specified on the constructor, and that property will contain one or more data objects of the application root type. In the event that the query returns no data, the special root object will still be returned but the containment property for the application root type will be empty. Errors/ExceptionsSDO_DAS_Relational::executePreparedQuery can throw an SDO_DAS_Relational_Exception if it is unable to construct the data graph correctly. This can occur for a number of reasons: for example if it finds that it does not have primary keys in the result set for all the objects. It also catches any PDO exceptions and obtains PDO diagnostic information which it includes in an SDO_DAS_Relational_Exception which it then throws. Examples
Example #1 Retrieving a data object using executePreparedQuery In this example a single data object is retrieved from the database - or possibly more than one if there is more than one company called 'Acme'. For each company returned, the name and id properties are echoed. Other examples of the use of executePreparedQuery can be found in the example code supplied in sdo/DAS/Relational/Scenarios.
<?php |