xref: /PHP-8.0/ext/oci8/tests/define4.phpt (revision 58a65c4b)
1--TEST--
2oci_define_by_name() on partial number of columns
3--SKIPIF--
4<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
5--FILE--
6<?php
7
8require(__DIR__."/connect.inc");
9
10// Initialize
11
12$stmtarray = array(
13    "drop table define4_tab",
14    "create table define4_tab (value number, string varchar(10))",
15    "insert into define4_tab (value, string) values (1234, 'some')",
16);
17
18oci8_test_sql_execute($c, $stmtarray);
19
20// Run test
21
22$stmt = oci_parse($c, "select value, string from define4_tab");
23
24echo "Test 1\n";
25// Only one of the two columns is defined
26var_dump(oci_define_by_name($stmt, "STRING", $string));
27
28oci_execute($stmt);
29
30echo "Test 2\n";
31
32while (oci_fetch($stmt)) {
33    var_dump(oci_result($stmt, 'VALUE'));
34    var_dump($string);
35    var_dump(oci_result($stmt, 'STRING'));
36    var_dump($string);
37    var_dump(oci_result($stmt, 'VALUE'));
38    var_dump(oci_result($stmt, 'STRING'));
39}
40
41echo "Test 3\n";
42var_dump(oci_free_statement($stmt));
43var_dump($string);
44
45try {
46    var_dump(oci_result($stmt, 'STRING'));
47} catch(\TypeError $exception) {
48    var_dump($exception->getMessage());
49}
50// Cleanup
51
52$stmtarray = array(
53    "drop table define4_tab"
54);
55
56oci8_test_sql_execute($c, $stmtarray);
57
58echo "Done\n";
59
60?>
61--EXPECTF--
62Test 1
63bool(true)
64Test 2
65string(4) "1234"
66string(4) "some"
67string(4) "some"
68string(4) "some"
69string(4) "1234"
70string(4) "some"
71Test 3
72bool(true)
73string(4) "some"
74string(%d) "oci_result(): supplied resource is not a valid oci8 statement resource"
75Done
76