mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-29 23:38:56 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@172447 c90b9560-bf6c-de11-be94-00142212c4b1
57 lines
1.8 KiB
XML
57 lines
1.8 KiB
XML
<?xml version='1.0' encoding='iso-8859-1'?>
|
|
<!-- $Revision: 1.3 $ -->
|
|
<refentry id='function.pdo-execute'>
|
|
<refnamediv>
|
|
<refname>execute</refname>
|
|
<refpurpose>Executes a prepared statement</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>execute</methodname>
|
|
<methodparam choice='opt'><type>array</type><parameter>parameters</parameter></methodparam>
|
|
</methodsynopsis>
|
|
&warn.experimental.func;
|
|
<para>
|
|
Execute the prepared statement. If the prepared statement included
|
|
parameter markers, you must either:
|
|
<itemizedlist>
|
|
<listitem><para>call <function>bindParam</function> to bind PHP variables
|
|
to the parameter markers: bound variables pass their value as input and receive the
|
|
output value, if any, of their associated parameter markers</para></listitem>
|
|
<listitem><para>or pass an array of parameter values</para></listitem>
|
|
</itemizedlist>
|
|
<example><title>Execute a prepared statement with bound variables</title>
|
|
<programlisting role='php'>
|
|
<![CDATA[
|
|
<?php
|
|
/* Execute a prepared statement by binding PHP variables */
|
|
$calories = 150;
|
|
$colour = 'red';
|
|
$sth = $dbh->prepare('SELECT name, colour, calories
|
|
FROM fruit
|
|
WHERE calories < ? AND colour = ?');
|
|
$sth->bindParam(1, $calories, PDO_PARAM_INT);
|
|
$sth->bindParam(2, $colour, PDO_PARAM_STR, 12);
|
|
$sth->execute();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example><title>Execute a prepared statement by passing an array of
|
|
values</title>
|
|
<programlisting role='php'>
|
|
<![CDATA[
|
|
<?php
|
|
/* Execute a prepared statement by passing an array of values */
|
|
$sth = $dbh->prepare('SELECT name, colour, calories
|
|
FROM fruit
|
|
WHERE calories < ? AND colour = ?');
|
|
$sth->execute(array(150, 'red'));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|