Add <programlisting> with example code for executePreparedQuery()

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@192009 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Matthew Peters 2005-08-01 09:23:02 +00:00
parent 92307b247e
commit 785c36e763

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!-- $Revision: 1.1 $ -->
<!-- $Revision: 1.2 $ -->
<refentry id="function.SDO-DAS-Relational-executePreparedQuery">
<refnamediv>
<refname>SDO_DAS_Relational::executePreparedQuery</refname>
@ -196,10 +196,63 @@ $dbh = new PDO("mysql:dbname=COMPANYDB;host=localhost",DATABASE_USER,DATABASE_PA
<refsect1 role="examples">
&reftitle.examples;
<para>
Please see the
<link linkend='sdo.das.rel.examples'>Examples</link>
section in the general information about the
Relational DAS for many examples of calling this method.
<example>
<title>Retrieving a data object using executePreparedQuery</title>
<para>
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
<varname>name</varname>
and
<varname>id</varname>
properties are echoed.
</para>
<para>
Other examples of the use of
<function>executePreparedQuery</function>
can be found in the example code supplied in
<filename>sdo/DAS/Relational/Scenarios</filename>
.
</para>
<programlisting role="php" id="sdo.das.rel.functions.epq.1c-R">
<![CDATA[
<?php
require_once 'SDO/DAS/Relational.php';
require_once 'company_metadata.inc.php';
/**************************************************************
* Construct the DAS with the metadata
***************************************************************/
$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_reference_metadata);
/**************************************************************
* Get a database connection
***************************************************************/
$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD);
/**************************************************************
* Issue a query to obtain a company object - possibly more if they exist
* Use a prepared query with a placeholder.
***************************************************************/
$name = 'Acme';
$pdo_stmt = $dbh->prepare('select name, id from company where name=?');
$root = $das->executePreparedQuery(
$dbh,
$pdo_stmt,
array($name),
array('company.name', 'company.id'));
/**************************************************************
* Echo name and id
***************************************************************/
foreach ($root['company'] as $company) {
echo "Company obtained from the database has name = " .
$company['name'] . " and id " . $company['id'] . "\n";
}
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>