xref: /php-src/ext/pdo_mysql/tests/bug_44707.phpt (revision 4bb75d56)
1--TEST--
2Bug #44707 (The MySQL PDO driver resets variable content after bindParam on tinyint field)
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12require_once __DIR__ . '/inc/mysql_pdo_test.inc';
13$db = MySQLPDOTest::factory();
14$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
15
16function bug_44707($db) {
17    $db->exec('CREATE TABLE test_44707(id INT, mybool TINYINT)');
18
19    $id = 1;
20    $mybool = false;
21    var_dump($mybool);
22
23    $stmt = $db->prepare('INSERT INTO test_44707(id, mybool) VALUES (?, ?)');
24    $stmt->bindParam(1, $id);
25    $stmt->bindParam(2, $mybool, PDO::PARAM_BOOL);
26    var_dump($mybool);
27
28    $stmt->execute();
29    var_dump($mybool);
30
31    $stmt = $db->query('SELECT * FROM test_44707');
32    var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
33
34    $stmt = $db->prepare('INSERT INTO test_44707(id, mybool) VALUES (?, ?)');
35    $stmt->bindParam(1, $id);
36    // INT and integer work well together
37    $stmt->bindParam(2, $mybool, PDO::PARAM_INT);
38    $stmt->execute();
39
40    $stmt = $db->query('SELECT * FROM test_44707');
41    var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
42}
43
44
45/*
46// This is beyond the control of the driver... - the driver never gets in touch with bound values
47print "Emulated Prepared Statements\n";
48$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
49bug_44707($db);
50*/
51
52print "Native Prepared Statements\n";
53$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
54bug_44707($db);
55
56print "done!";
57?>
58--CLEAN--
59<?php
60require_once __DIR__ . '/inc/mysql_pdo_test.inc';
61$db = MySQLPDOTest::factory();
62$db->exec('DROP TABLE IF EXISTS test_44707');
63?>
64--EXPECT--
65Native Prepared Statements
66bool(false)
67bool(false)
68bool(false)
69array(1) {
70  [0]=>
71  array(2) {
72    ["id"]=>
73    string(1) "1"
74    ["mybool"]=>
75    string(1) "0"
76  }
77}
78array(2) {
79  [0]=>
80  array(2) {
81    ["id"]=>
82    string(1) "1"
83    ["mybool"]=>
84    string(1) "0"
85  }
86  [1]=>
87  array(2) {
88    ["id"]=>
89    string(1) "1"
90    ["mybool"]=>
91    string(1) "0"
92  }
93}
94done!
95