File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ PDO_sqlite: Test PARAM_BINARY with a BLOB
3
+ --EXTENSIONS--
4
+ pdo_sqlite
5
+ --FILE--
6
+ <?php
7
+
8
+ // This is a one pixel PNG of rgba(0, 0, 0, 255)
9
+ $ binary = base64_decode ("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NgYGD4DwABBAEAwS2OUAAAAABJRU5ErkJggg== " );
10
+
11
+ $ db = new PDO ("sqlite::memory: " );
12
+ $ db ->exec ("CREATE TABLE test_binary(field BLOB) " );
13
+
14
+ $ stmt = $ db ->prepare ("INSERT INTO test_binary(field) VALUES (?) " );
15
+ $ stmt ->bindParam (1 , $ binary , PDO ::PARAM_BINARY );
16
+ $ result = $ stmt ->execute ();
17
+ var_dump ($ result );
18
+
19
+ // We have to bind the result as a PDO binary/SQLite BLOB,
20
+ // because just getting the results otherwise will be
21
+ // considered a "null" type to SQLite.
22
+ $ stmt = $ db ->prepare ("SELECT field FROM test_binary " );
23
+ $ result = $ stmt ->execute ();
24
+ $ binary = "" ;
25
+ $ stmt ->bindColumn (1 , $ binary , PDO ::PARAM_BINARY );
26
+ $ result = $ stmt ->execute ();
27
+ $ result = $ stmt ->fetch ();
28
+
29
+ var_dump (base64_encode ($ binary ));
30
+ var_dump ($ stmt ->getColumnMeta (0 )["pdo_type " ]);
31
+ var_dump ($ stmt ->getColumnMeta (0 )["sqlite:decl_type " ]);
32
+ ?>
33
+ --EXPECT--
34
+ bool(true)
35
+ string(96) "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NgYGD4DwABBAEAwS2OUAAAAABJRU5ErkJggg=="
36
+ int(6)
37
+ string(4) "BLOB"
You can’t perform that action at this time.
0 commit comments