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