xref: /PHP-7.1/ext/oci8/tests/define5.phpt (revision 113213f0)
1--TEST--
2oci_define_by_name() for statement re-execution
3--SKIPIF--
4<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
5--FILE--
6<?php
7
8require(dirname(__FILE__)."/connect.inc");
9
10// Initialize
11
12$stmtarray = array(
13    "drop table define5_tab",
14    "create table define5_tab (id number, string varchar(10))",
15    "insert into define5_tab (id, string) values (1, 'some')",
16    "insert into define5_tab (id, string) values (2, 'thing')",
17);
18
19oci8_test_sql_execute($c, $stmtarray);
20
21// Run test
22
23echo "Test 1 - must do define before execute\n";
24$stmt = oci_parse($c, "select string from define5_tab where id = 1");
25oci_execute($stmt);
26var_dump(oci_define_by_name($stmt, "STRING", $string));
27while (oci_fetch($stmt)) {
28	var_dump($string);  // gives NULL
29	var_dump(oci_result($stmt, 'STRING'));
30}
31
32echo "Test 2 - normal define order\n";
33$stmt = oci_parse($c, "select string from define5_tab where id = 1");
34var_dump(oci_define_by_name($stmt, "STRING", $string));
35oci_execute($stmt);
36
37while (oci_fetch($stmt)) {
38	var_dump($string);
39}
40
41echo "Test 3 - no new define done\n";
42$stmt = oci_parse($c, "select string from define5_tab where id = 2");
43oci_execute($stmt);
44while (oci_fetch($stmt)) {
45	var_dump($string); // not updated with new value
46	var_dump(oci_result($stmt, 'STRING'));
47}
48
49// Cleanup
50
51$stmtarray = array(
52    "drop table define5_tab"
53);
54
55oci8_test_sql_execute($c, $stmtarray);
56
57echo "Done\n";
58
59?>
60--EXPECT--
61Test 1 - must do define before execute
62bool(true)
63NULL
64string(4) "some"
65Test 2 - normal define order
66bool(true)
67string(4) "some"
68Test 3 - no new define done
69string(4) "some"
70string(5) "thing"
71Done
72