-
Notifications
You must be signed in to change notification settings - Fork 102
/
bindparam.xml
201 lines (188 loc) · 6.48 KB
/
bindparam.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 28529d3539b850e870e3aa97570f4db0e53daa03 Maintainer: ichenshy Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="pdostatement.bindparam" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>PDOStatement::bindParam</refname>
<refpurpose>
绑定一个参数到指定的变量名
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="PDOStatement">
<modifier>public</modifier> <type>bool</type><methodname>PDOStatement::bindParam</methodname>
<methodparam><type class="union"><type>string</type><type>int</type></type><parameter>param</parameter></methodparam>
<methodparam><type>mixed</type><parameter role="reference">var</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>type</parameter><initializer>PDO::PARAM_STR</initializer></methodparam>
<methodparam choice="opt"><type>int</type><parameter>maxLength</parameter><initializer>0</initializer></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>driverOptions</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
绑定一个PHP变量到用作预处理的SQL语句中的对应命名占位符或问号占位符。 不同于 <methodname>PDOStatement::bindValue</methodname> ,此变量作为引用被绑定,并只在 <methodname>PDOStatement::execute</methodname> 被调用的时候才取其值。
</para>
<para>
大多数参数是输入参数,即,参数以只读的方式用来建立查询(但仍然可以根据 <parameter>type</parameter> 进行转换)。一些驱动支持调用存储过程并作为输出参数返回数据,一些支持作为输入/输出参数,既发送数据又接收更新后的数据。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>param</parameter></term>
<listitem>
<para>
参数标识符。对于使用命名占位符的预处理语句,应是类似 <varname>:name</varname> 形式的参数名。对于使用问号占位符的预处理语句,应是以1开始索引的参数位置。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>var</parameter></term>
<listitem>
<para>
绑定到 SQL 语句参数的 PHP 变量名。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>type</parameter></term>
<listitem>
<para>
使用 <link linkend="pdo.constants"><literal>PDO::PARAM_*</literal> 常量</link>明确地指定参数的类型。要从存储过程中返回 INOUT 参数,需要为 <parameter>type</parameter> 参数使用按位或操作符去设置 <constant>PDO::PARAM_INPUT_OUTPUT</constant> 位。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>maxLength</parameter></term>
<listitem>
<para>
数据类型的长度。为表明参数是一个存储过程的 OUT 参数,必须明确地设置此长度。
仅当 <parameter>type</parameter> 参数为 <constant>PDO::PARAM_INPUT_OUTPUT</constant> 时才有意义。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>driverOptions</parameter></term>
<listitem>
<para>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
&pdo.errors;
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example><title>执行一条使用命名占位符的预处理语句</title>
<programlisting role="php">
<![CDATA[
<?php
/* 通过绑定的 PHP 变量执行一条预处理语句 */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour');
$sth->bindParam('calories', $calories, PDO::PARAM_INT);
/* 名称也可以以冒号“:”为前缀(可选)*/
$sth->bindParam(':colour', $colour, PDO::PARAM_STR);
$sth->execute();
?>
]]>
</programlisting>
</example>
<example><title> 执行一条使用问号占位符的预处理语句 </title>
<programlisting role="php">
<![CDATA[
<?php
/* 通过绑定的 PHP 变量执行一条预处理语句 */
$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);
$sth->execute();
?>
]]>
</programlisting>
</example>
<!--
<example><title>Pass a NULL value into a prepared statement</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 < :calories AND colour = :colour');
$sth->bindParam(':calories', $calories, PDO::PARAM_INT);
/* Find fruit with a NULL value in the colour column */
$sth->bindParam(':colour', $colour, PDO::PARAM_NULL);
$sth->execute();
?>
]]>
</programlisting>
</example>
-->
<example><title>使用 INOUT 参数调用一个存储过程</title>
<programlisting role="php">
<![CDATA[
<?php
/* 使用 INOUT 参数调用一个存储过程 */
$colour = 'red';
$sth = $dbh->prepare('CALL puree_fruit(?)');
$sth->bindParam(1, $colour, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 12);
$sth->execute();
print "After pureeing fruit, the colour is: $colour";
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>PDO::prepare</methodname></member>
<member><methodname>PDOStatement::execute</methodname></member>
<member><methodname>PDOStatement::bindValue</methodname></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->