xref: /PHP-8.2/ext/oci8/tests/define2.phpt (revision b5a14e6c)
1--TEST--
2Test oci_define_by_name types
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
8require(__DIR__.'/skipif.inc');
9?>
10--FILE--
11<?php
12
13require(__DIR__."/connect.inc");
14
15$stmtarray = array(
16    "drop table phptestrawtable",
17    "create table phptestrawtable( id number(10), fileimage raw(1000))"
18);
19
20oci8_test_sql_execute($c, $stmtarray);
21
22$stmt = oci_parse ($c, "insert into phptestrawtable (id, fileimage) values (:id, :fileimage)");
23$i=1;
24$fileimage = file_get_contents( __DIR__."/test.gif");
25$fileimage = substr($fileimage, 0, 300);
26var_dump(md5($fileimage));
27
28oci_bind_by_name( $stmt, ":id", $i, -1);
29oci_bind_by_name( $stmt, ":fileimage", $fileimage, -1, SQLT_BIN);
30oci_execute($stmt, OCI_DEFAULT);
31oci_commit($c);
32
33echo "Test 1\n";
34$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
35var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi));
36oci_execute($stmt);
37
38while (oci_fetch($stmt)) {
39    var_dump($fi);
40    echo "file md5:" . md5($fi) . "\n";
41}
42
43echo "Test 2\n";
44$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
45var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi));
46oci_execute($stmt);
47
48while (oci_fetch($stmt)) {
49    var_dump($fi);
50    echo "file md5:" . md5($fi) . "\n";
51}
52
53echo "Test 3 - test repeatability\n";
54$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
55var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi, SQLT_STR));
56oci_execute($stmt);
57
58while (oci_fetch($stmt)) {
59    var_dump($fi);
60    echo "file md5:" . md5($fi) . "\n";
61}
62
63echo "Test 4 - wrong type\n";
64$stmt = oci_parse($c, "SELECT fileimage FROM phptestrawtable");
65var_dump(oci_define_by_name($stmt, 'FILEIMAGE', $fi, SQLT_RSET));
66oci_execute($stmt);
67
68while (oci_fetch($stmt)) {
69    var_dump($fi);
70    echo "file md5:" . md5($fi) . "\n";
71}
72
73// Cleanup
74
75$stmtarray = array(
76    "drop table phptestrawtable"
77);
78
79oci8_test_sql_execute($c, $stmtarray);
80
81echo "Done\n";
82?>
83--EXPECTF--
84string(32) "88b274d7a257ac6f70435b83abd4e26e"
85Test 1
86bool(true)
87string(300) "GIF89%s"
88file md5:88b274d7a257ac6f70435b83abd4e26e
89Test 2
90bool(true)
91string(300) "GIF89%s"
92file md5:88b274d7a257ac6f70435b83abd4e26e
93Test 3 - test repeatability
94bool(true)
95string(600) "47494638396178004300E66A007F82B839374728252ACCCDE2A1A4CBD3D5E7B2B4D44342588386B98283B35252729092C2C2C4DEAAACD04C4B635B5C83DDDEEC3B383C6E71A56A6D9D61638D7579B17B7EB5E5E6F0999CC68C8DC1B9BAD96B6B924E4E6B7174A97A7AA3888BBD7274A37473988E90C15A5B7EE2E3EF7B7DADA4A5D06D70A27276AC9596C8BBBDD97478AE8588BB9295C3D8D9EA9292C46466926B6E9FA5A8CE9496C52E2B2F535168B3B4D76C6A8C5C5B768A8DBF666896686A9A9C9FC8312E39AEB0D39C9CCD5556789EA1CA9699C58182AF6769973F3D50BCBEDA5E60899899C88C8EBF898ABA57587CB6B7D7D5D7E8221E206C6F9ECED0E4BFC0DC777BB47678A75F5E7D9999CC6E6F987377AE221E1FFFFFFF908E8F595657C7C6C7EEEEF5D5D4D5F6F6"
96file md5:80bb3201e2a8bdcb8ab3e1a44a82bb8a
97Test 4 - wrong type
98bool(true)
99
100Warning: oci_fetch(): ORA-00932: inconsistent datatypes%s on line %d
101Done
102