xref: /PHP-8.3/ext/oci8/tests/bind_query.phpt (revision a53e5617)
1--TEST--
2Bind with various WHERE conditions
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11
12require __DIR__.'/connect.inc';
13
14// Initialization
15
16$stmtarray = array(
17    "drop table bind_query_tab",
18    "create table bind_query_tab (empno number(4), ename varchar2(10), sal number(7,2))",
19    "insert into bind_query_tab values (7934, 'MILLER', 1300)",
20    "insert into bind_query_tab values (7902, 'FORD', 3000)"
21);
22
23oci8_test_sql_execute($c, $stmtarray);
24
25// Run Test
26
27echo "Test 1\n";
28
29$e = 7934;
30
31$s = oci_parse($c, "select ename from bind_query_tab where empno = :eno");
32oci_bind_by_name( $s, ":eno", $e, -1, SQLT_INT);
33oci_execute($s);
34var_dump(oci_fetch_row($s));
35
36echo "Test 2\n";
37
38$v = 1000;
39$s = oci_parse($c, 'select ename from bind_query_tab where sal > :v order by ename');
40oci_bind_by_name( $s, ":v", $v);
41oci_define_by_name($s, "ENAME", $ename, 20);
42oci_execute($s);
43while (oci_fetch($s)) {
44    var_dump($ename);
45}
46
47
48echo "Test 3\n";
49
50$s = oci_parse($c, 'select ename from bind_query_tab where sal > :v order by ename');
51oci_bind_by_name( $s, ":v", $v);
52$v = 2000;
53oci_define_by_name($s, "ENAME", $ename, 20);
54oci_execute($s);
55while (oci_fetch($s)) {
56    var_dump($ename);
57}
58
59
60// Clean up
61
62$stmtarray = array(
63    "drop table bind_query_tab"
64);
65
66oci8_test_sql_execute($c, $stmtarray);
67
68?>
69--EXPECT--
70Test 1
71array(1) {
72  [0]=>
73  string(6) "MILLER"
74}
75Test 2
76string(4) "FORD"
77string(6) "MILLER"
78Test 3
79string(4) "FORD"
80