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