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