1
1
--TEST--
2
- GH-13384 Fixed GH-13167 Fixed the behavior when an inappropriate value was passed to `bindValue`.
2
+ GH-13384 Fixed GH-13167 Fixed the behavior when an inappropriate value was passed to `bindValue` and `bindParam` .
3
3
--EXTENSIONS--
4
4
pdo_mysql
5
5
--SKIPIF--
@@ -16,22 +16,53 @@ $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
16
16
17
17
$ db ->exec ('CREATE TABLE test_gh13384 (mode TINYINT) ' );
18
18
19
- $ stmt = $ db ->prepare ('INSERT INTO test_gh13384 (mode) VALUES (?) ' );
20
- $ stmt ->bindValue (1 , new DateTime (), PDO ::PARAM_INT );
19
+ $ stringableObject = new class () {
20
+ public function __toString (): string
21
+ {
22
+ return 'I am stringable object ' ;
23
+ }
24
+ };
21
25
22
- var_dump ($ stmt ->execute ());
23
- var_dump ($ db ->errorInfo ());
24
- var_dump ($ db ->query ('SELECT * FROM test_gh13384 ' )->fetchAll ());
26
+ echo "Stringable object, bindValue: \n" ;
27
+ try {
28
+ $ stmt = $ db ->prepare ('INSERT INTO test_gh13384 (mode) VALUES (?) ' );
29
+ $ stmt ->bindValue (1 , $ stringableObject , PDO ::PARAM_INT );
30
+ $ stmt ->execute ();
31
+ } catch (Throwable $ e ) {
32
+ echo $ e ->getMessage ()."\n\n" ;
33
+ }
34
+
35
+ echo "Normal object, bindValue: \n" ;
36
+ try {
37
+ $ stmt = $ db ->prepare ('INSERT INTO test_gh13384 (mode) VALUES (?) ' );
38
+ $ stmt ->bindValue (1 , new DateTime (), PDO ::PARAM_INT );
39
+ $ stmt ->execute ();
40
+ } catch (Throwable $ e ) {
41
+ echo $ e ->getMessage ()."\n\n" ;
42
+ }
43
+
44
+ echo "Array, bindParam: \n" ;
45
+ try {
46
+ $ stmt = $ db ->prepare ('INSERT INTO test_gh13384 (mode) VALUES (?) ' );
47
+ $ param = ['aaa ' ];
48
+ $ stmt ->bindParam (1 , $ param , PDO ::PARAM_INT );
49
+ $ stmt ->execute ();
50
+ } catch (Throwable $ e ) {
51
+ echo $ e ->getMessage ();
52
+ }
25
53
?>
26
54
--CLEAN--
27
55
<?php
28
56
require_once __DIR__ . '/inc/mysql_pdo_test.inc ' ;
29
57
$ db = MySQLPDOTest::factory ();
30
58
$ db ->exec ('DROP TABLE IF EXISTS test_gh13384 ' );
31
59
?>
32
- --EXPECTF--
33
- Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in %s
34
- Stack trace:
35
- #0 %s: PDOStatement->execute()
36
- #1 {main}
37
- thrown in %s
60
+ --EXPECT--
61
+ Stringable object, bindValue:
62
+ SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'I am stringable object' for column 'mode' at row 1
63
+
64
+ Normal object, bindValue:
65
+ SQLSTATE[HY105]: Invalid parameter type: Expected a scalar value or null
66
+
67
+ Array, bindParam:
68
+ SQLSTATE[HY105]: Invalid parameter type: Expected a scalar value or null
0 commit comments