1--TEST-- 2Bug #44707 (The MySQL PDO driver resets variable content after bindParam on tinyint field) 3--EXTENSIONS-- 4pdo 5pdo_mysql 6--SKIPIF-- 7<?php 8require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 9 10MySQLPDOTest::skip(); 11 12$db = MySQLPDOTest::factory(); 13$stmt = $db->query('SELECT VERSION() as _version'); 14$row = $stmt->fetch(PDO::FETCH_ASSOC); 15$matches = array(); 16if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches)) 17 die(sprintf("skip Cannot determine MySQL Server version\n")); 18 19$version = $matches[1] * 10000 + $matches[2] * 100 + $matches[3]; 20if ($version < 41000) 21 die(sprintf("skip Will work different with MySQL Server < 4.1.0, found %d.%02d.%02d (%d)\n", 22 $matches[1], $matches[2], $matches[3], $version)); 23?> 24--FILE-- 25<?php 26require __DIR__ . '/config.inc'; 27require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 28$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); 29 30function bug_44707($db) { 31 32 $db->exec('DROP TABLE IF EXISTS test'); 33 $db->exec('CREATE TABLE test(id INT, mybool TINYINT)'); 34 35 $id = 1; 36 $mybool = false; 37 var_dump($mybool); 38 39 $stmt = $db->prepare('INSERT INTO test(id, mybool) VALUES (?, ?)'); 40 $stmt->bindParam(1, $id); 41 $stmt->bindParam(2, $mybool, PDO::PARAM_BOOL); 42 var_dump($mybool); 43 44 $stmt->execute(); 45 var_dump($mybool); 46 47 $stmt = $db->query('SELECT * FROM test'); 48 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 49 50 $stmt = $db->prepare('INSERT INTO test(id, mybool) VALUES (?, ?)'); 51 $stmt->bindParam(1, $id); 52 // INT and integer work well together 53 $stmt->bindParam(2, $mybool, PDO::PARAM_INT); 54 $stmt->execute(); 55 56 $stmt = $db->query('SELECT * FROM test'); 57 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 58 59} 60 61 62/* 63// This is beyond the control of the driver... - the driver never gets in touch with bound values 64print "Emulated Prepared Statements\n"; 65$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); 66bug_44707($db); 67*/ 68 69print "Native Prepared Statements\n"; 70$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); 71bug_44707($db); 72 73print "done!"; 74?> 75--EXPECT-- 76Native Prepared Statements 77bool(false) 78bool(false) 79bool(false) 80array(1) { 81 [0]=> 82 array(2) { 83 ["id"]=> 84 string(1) "1" 85 ["mybool"]=> 86 string(1) "0" 87 } 88} 89array(2) { 90 [0]=> 91 array(2) { 92 ["id"]=> 93 string(1) "1" 94 ["mybool"]=> 95 string(1) "0" 96 } 97 [1]=> 98 array(2) { 99 ["id"]=> 100 string(1) "1" 101 ["mybool"]=> 102 string(1) "0" 103 } 104} 105done! 106