1 | <HTML
|
---|
2 | ><HEAD
|
---|
3 | ><TITLE
|
---|
4 | >OCIBindByName</TITLE
|
---|
5 | ><META
|
---|
6 | NAME="GENERATOR"
|
---|
7 | CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
---|
8 | REL="HOME"
|
---|
9 | TITLE="Manuál PHP"
|
---|
10 | HREF="index.html"><LINK
|
---|
11 | REL="UP"
|
---|
12 | TITLE="Oracle 8 functions"
|
---|
13 | HREF="ref.oci8.html"><LINK
|
---|
14 | REL="PREVIOUS"
|
---|
15 | TITLE="Oracle 8 functions"
|
---|
16 | HREF="ref.oci8.html"><LINK
|
---|
17 | REL="NEXT"
|
---|
18 | TITLE="OCICancel"
|
---|
19 | HREF="function.ocicancel.html"><META
|
---|
20 | HTTP-EQUIV="Content-type"
|
---|
21 | CONTENT="text/html; charset=ISO-8859-2"></HEAD
|
---|
22 | ><BODY
|
---|
23 | CLASS="refentry"
|
---|
24 | BGCOLOR="#FFFFFF"
|
---|
25 | TEXT="#000000"
|
---|
26 | LINK="#0000FF"
|
---|
27 | VLINK="#840084"
|
---|
28 | ALINK="#0000FF"
|
---|
29 | ><DIV
|
---|
30 | CLASS="NAVHEADER"
|
---|
31 | ><TABLE
|
---|
32 | SUMMARY="Header navigation table"
|
---|
33 | WIDTH="100%"
|
---|
34 | BORDER="0"
|
---|
35 | CELLPADDING="0"
|
---|
36 | CELLSPACING="0"
|
---|
37 | ><TR
|
---|
38 | ><TH
|
---|
39 | COLSPAN="3"
|
---|
40 | ALIGN="center"
|
---|
41 | >Manuál PHP</TH
|
---|
42 | ></TR
|
---|
43 | ><TR
|
---|
44 | ><TD
|
---|
45 | WIDTH="10%"
|
---|
46 | ALIGN="left"
|
---|
47 | VALIGN="bottom"
|
---|
48 | ><A
|
---|
49 | HREF="ref.oci8.html"
|
---|
50 | ACCESSKEY="P"
|
---|
51 | >Pøedcházející</A
|
---|
52 | ></TD
|
---|
53 | ><TD
|
---|
54 | WIDTH="80%"
|
---|
55 | ALIGN="center"
|
---|
56 | VALIGN="bottom"
|
---|
57 | ></TD
|
---|
58 | ><TD
|
---|
59 | WIDTH="10%"
|
---|
60 | ALIGN="right"
|
---|
61 | VALIGN="bottom"
|
---|
62 | ><A
|
---|
63 | HREF="function.ocicancel.html"
|
---|
64 | ACCESSKEY="N"
|
---|
65 | >Dal¹í</A
|
---|
66 | ></TD
|
---|
67 | ></TR
|
---|
68 | ></TABLE
|
---|
69 | ><HR
|
---|
70 | ALIGN="LEFT"
|
---|
71 | WIDTH="100%"></DIV
|
---|
72 | ><H1
|
---|
73 | ><A
|
---|
74 | NAME="function.ocibindbyname"
|
---|
75 | ></A
|
---|
76 | >OCIBindByName</H1
|
---|
77 | ><DIV
|
---|
78 | CLASS="refnamediv"
|
---|
79 | ><A
|
---|
80 | NAME="AEN61915"
|
---|
81 | ></A
|
---|
82 | ><P
|
---|
83 | > (PHP 3>= 3.0.4, PHP 4 )</P
|
---|
84 | >OCIBindByName --
|
---|
85 | Bind a PHP variable to an Oracle Placeholder
|
---|
86 | </DIV
|
---|
87 | ><DIV
|
---|
88 | CLASS="refsect1"
|
---|
89 | ><A
|
---|
90 | NAME="AEN61918"
|
---|
91 | ></A
|
---|
92 | ><H2
|
---|
93 | >Description</H2
|
---|
94 | >bool <B
|
---|
95 | CLASS="methodname"
|
---|
96 | >OCIBindByName</B
|
---|
97 | > ( int stmt, string ph_name, mixed & variable, int length [, int type])<BR
|
---|
98 | ></BR
|
---|
99 | ><P
|
---|
100 | > <B
|
---|
101 | CLASS="function"
|
---|
102 | >OCIBindByName()</B
|
---|
103 | > binds the PHP variable
|
---|
104 | <TT
|
---|
105 | CLASS="parameter"
|
---|
106 | ><I
|
---|
107 | >variable</I
|
---|
108 | ></TT
|
---|
109 | > to the Oracle placeholder
|
---|
110 | <TT
|
---|
111 | CLASS="parameter"
|
---|
112 | ><I
|
---|
113 | >ph_name</I
|
---|
114 | ></TT
|
---|
115 | >. Whether it will be used for
|
---|
116 | input or output will be determined run-time, and the necessary
|
---|
117 | storage space will be allocated. The
|
---|
118 | <TT
|
---|
119 | CLASS="parameter"
|
---|
120 | ><I
|
---|
121 | >length</I
|
---|
122 | ></TT
|
---|
123 | > parameter sets the maximum length
|
---|
124 | for the bind. If you set <TT
|
---|
125 | CLASS="parameter"
|
---|
126 | ><I
|
---|
127 | >length</I
|
---|
128 | ></TT
|
---|
129 | > to -1
|
---|
130 | <B
|
---|
131 | CLASS="function"
|
---|
132 | >OCIBindByName()</B
|
---|
133 | > will use the current length of
|
---|
134 | <TT
|
---|
135 | CLASS="parameter"
|
---|
136 | ><I
|
---|
137 | >variable</I
|
---|
138 | ></TT
|
---|
139 | > to set the maximum length.
|
---|
140 | </P
|
---|
141 | ><P
|
---|
142 | > If you need to bind an abstract Datatype (LOB/ROWID/BFILE) you
|
---|
143 | need to allocate it first using
|
---|
144 | <A
|
---|
145 | HREF="function.ocinewdescriptor.html"
|
---|
146 | ><B
|
---|
147 | CLASS="function"
|
---|
148 | >OCINewDescriptor()</B
|
---|
149 | ></A
|
---|
150 | > function. The
|
---|
151 | <TT
|
---|
152 | CLASS="parameter"
|
---|
153 | ><I
|
---|
154 | >length</I
|
---|
155 | ></TT
|
---|
156 | > is not used for abstract Datatypes
|
---|
157 | and should be set to -1. The <TT
|
---|
158 | CLASS="parameter"
|
---|
159 | ><I
|
---|
160 | >type</I
|
---|
161 | ></TT
|
---|
162 | > variable
|
---|
163 | tells oracle, what kind of descriptor we want to use. Possible
|
---|
164 | values are: OCI_B_FILE (Binary-File), OCI_B_CFILE
|
---|
165 | (Character-File), OCI_B_CLOB (Character-LOB), OCI_B_BLOB
|
---|
166 | (Binary-LOB) and OCI_B_ROWID (ROWID).
|
---|
167 | </P
|
---|
168 | ><TABLE
|
---|
169 | WIDTH="100%"
|
---|
170 | BORDER="0"
|
---|
171 | CELLPADDING="0"
|
---|
172 | CELLSPACING="0"
|
---|
173 | CLASS="EXAMPLE"
|
---|
174 | ><TR
|
---|
175 | ><TD
|
---|
176 | ><DIV
|
---|
177 | CLASS="example"
|
---|
178 | ><A
|
---|
179 | NAME="AEN61950"
|
---|
180 | ></A
|
---|
181 | ><P
|
---|
182 | ><B
|
---|
183 | >Pøíklad 1. OCIDefineByName</B
|
---|
184 | ></P
|
---|
185 | ><TABLE
|
---|
186 | BORDER="0"
|
---|
187 | BGCOLOR="#E0E0E0"
|
---|
188 | CELLPADDING="5"
|
---|
189 | ><TR
|
---|
190 | ><TD
|
---|
191 | ><PRE
|
---|
192 | CLASS="programlisting"
|
---|
193 | ><?php
|
---|
194 | /* OCIBindByPos example thies@thieso.net (980221)
|
---|
195 | inserts 3 records into emp, and uses the ROWID for updating the
|
---|
196 | records just after the insert.
|
---|
197 | */
|
---|
198 |
|
---|
199 | $conn = OCILogon("scott","tiger");
|
---|
200 |
|
---|
201 | $stmt = OCIParse($conn,"insert into emp (empno, ename) ".
|
---|
202 | "values (:empno,:ename) ".
|
---|
203 | "returning ROWID into :rid");
|
---|
204 |
|
---|
205 | $data = array(1111 => "Larry", 2222 => "Bill", 3333 => "Jim");
|
---|
206 |
|
---|
207 | $rowid = OCINewDescriptor($conn,OCI_D_ROWID);
|
---|
208 |
|
---|
209 | OCIBindByName($stmt,":empno",&$empno,32);
|
---|
210 | OCIBindByName($stmt,":ename",&$ename,32);
|
---|
211 | OCIBindByName($stmt,":rid",&$rowid,-1,OCI_B_ROWID);
|
---|
212 |
|
---|
213 | $update = OCIParse($conn,"update emp set sal = :sal where ROWID = :rid");
|
---|
214 | OCIBindByName($update,":rid",&$rowid,-1,OCI_B_ROWID);
|
---|
215 | OCIBindByName($update,":sal",&$sal,32);
|
---|
216 |
|
---|
217 | $sal = 10000;
|
---|
218 |
|
---|
219 | while (list($empno,$ename) = each($data)) {
|
---|
220 | OCIExecute($stmt);
|
---|
221 | OCIExecute($update);
|
---|
222 | }
|
---|
223 |
|
---|
224 | $rowid->free();
|
---|
225 |
|
---|
226 | OCIFreeStatement($update);
|
---|
227 | OCIFreeStatement($stmt);
|
---|
228 |
|
---|
229 | $stmt = OCIParse($conn,"select * from emp where empno in (1111,2222,3333)");
|
---|
230 | OCIExecute($stmt);
|
---|
231 | while (OCIFetchInto($stmt,&$arr,OCI_ASSOC)) {
|
---|
232 | var_dump($arr);
|
---|
233 | }
|
---|
234 | OCIFreeStatement($stmt);
|
---|
235 |
|
---|
236 | /* delete our "junk" from the emp table.... */
|
---|
237 | $stmt = OCIParse($conn,"delete from emp where empno in (1111,2222,3333)");
|
---|
238 | OCIExecute($stmt);
|
---|
239 | OCIFreeStatement($stmt);
|
---|
240 |
|
---|
241 | OCILogoff($conn);
|
---|
242 | ?></PRE
|
---|
243 | ></TD
|
---|
244 | ></TR
|
---|
245 | ></TABLE
|
---|
246 | ></DIV
|
---|
247 | ></TD
|
---|
248 | ></TR
|
---|
249 | ></TABLE
|
---|
250 | ><DIV
|
---|
251 | CLASS="warning"
|
---|
252 | ><P
|
---|
253 | ></P
|
---|
254 | ><TABLE
|
---|
255 | CLASS="warning"
|
---|
256 | BORDER="1"
|
---|
257 | WIDTH="100%"
|
---|
258 | ><TR
|
---|
259 | ><TD
|
---|
260 | ALIGN="CENTER"
|
---|
261 | ><B
|
---|
262 | >Varování</B
|
---|
263 | ></TD
|
---|
264 | ></TR
|
---|
265 | ><TR
|
---|
266 | ><TD
|
---|
267 | ALIGN="LEFT"
|
---|
268 | ><P
|
---|
269 | > It is a bad idea to use magic quotes and
|
---|
270 | <B
|
---|
271 | CLASS="function"
|
---|
272 | >OciBindByName()</B
|
---|
273 | > simultaneously as no quoting
|
---|
274 | is needed on quoted variables and any quotes magically applied
|
---|
275 | will be written into your database as
|
---|
276 | <B
|
---|
277 | CLASS="function"
|
---|
278 | >OciBindByName()</B
|
---|
279 | > is not able to distinguish
|
---|
280 | magically added quotings from those added by intention.
|
---|
281 | </P
|
---|
282 | ></TD
|
---|
283 | ></TR
|
---|
284 | ></TABLE
|
---|
285 | ></DIV
|
---|
286 | ></DIV
|
---|
287 | ><DIV
|
---|
288 | CLASS="NAVFOOTER"
|
---|
289 | ><HR
|
---|
290 | ALIGN="LEFT"
|
---|
291 | WIDTH="100%"><TABLE
|
---|
292 | SUMMARY="Footer navigation table"
|
---|
293 | WIDTH="100%"
|
---|
294 | BORDER="0"
|
---|
295 | CELLPADDING="0"
|
---|
296 | CELLSPACING="0"
|
---|
297 | ><TR
|
---|
298 | ><TD
|
---|
299 | WIDTH="33%"
|
---|
300 | ALIGN="left"
|
---|
301 | VALIGN="top"
|
---|
302 | ><A
|
---|
303 | HREF="ref.oci8.html"
|
---|
304 | ACCESSKEY="P"
|
---|
305 | >Pøedcházející</A
|
---|
306 | ></TD
|
---|
307 | ><TD
|
---|
308 | WIDTH="34%"
|
---|
309 | ALIGN="center"
|
---|
310 | VALIGN="top"
|
---|
311 | ><A
|
---|
312 | HREF="index.html"
|
---|
313 | ACCESSKEY="H"
|
---|
314 | >Domù</A
|
---|
315 | ></TD
|
---|
316 | ><TD
|
---|
317 | WIDTH="33%"
|
---|
318 | ALIGN="right"
|
---|
319 | VALIGN="top"
|
---|
320 | ><A
|
---|
321 | HREF="function.ocicancel.html"
|
---|
322 | ACCESSKEY="N"
|
---|
323 | >Dal¹í</A
|
---|
324 | ></TD
|
---|
325 | ></TR
|
---|
326 | ><TR
|
---|
327 | ><TD
|
---|
328 | WIDTH="33%"
|
---|
329 | ALIGN="left"
|
---|
330 | VALIGN="top"
|
---|
331 | >Oracle 8 functions</TD
|
---|
332 | ><TD
|
---|
333 | WIDTH="34%"
|
---|
334 | ALIGN="center"
|
---|
335 | VALIGN="top"
|
---|
336 | ><A
|
---|
337 | HREF="ref.oci8.html"
|
---|
338 | ACCESSKEY="U"
|
---|
339 | >Nahoru</A
|
---|
340 | ></TD
|
---|
341 | ><TD
|
---|
342 | WIDTH="33%"
|
---|
343 | ALIGN="right"
|
---|
344 | VALIGN="top"
|
---|
345 | >OCICancel</TD
|
---|
346 | ></TR
|
---|
347 | ></TABLE
|
---|
348 | ></DIV
|
---|
349 | ></BODY
|
---|
350 | ></HTML
|
---|
351 | >
|
---|