xref: /PHP-5.3/ext/pdo_mysql/tests/bug_44707.phpt (revision 973d7bad)
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(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
7require_once(dirname(__FILE__) . 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[0] * 10000 + $matches[1] * 100 + $matches[2];
19if ($version < 41000)
20	die(sprintf("skip Will work different with MySQL Server < 4.1.0, found %d.%02d.%02d (%d)\n",
21		$matches[0], $matches[1], $matches[2], $version));
22?>
23--FILE--
24<?php
25require dirname(__FILE__) . '/config.inc';
26require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
27$db = PDOTest::test_factory(dirname(__FILE__) . '/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	// From MySQL 4.1 on boolean and TINYINT don't match! INSERT will fail.
41	// Versions prior to 4.1 have a weak test and will accept this.
42	$stmt->bindParam(2, $mybool, PDO::PARAM_BOOL);
43	var_dump($mybool);
44
45	$stmt->execute();
46	var_dump($mybool);
47
48	$stmt = $db->query('SELECT * FROM test');
49	var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
50
51	$stmt = $db->prepare('INSERT INTO test(id, mybool) VALUES (?, ?)');
52	$stmt->bindParam(1, $id);
53	// INT and integer work well together
54	$stmt->bindParam(2, $mybool, PDO::PARAM_INT);
55	$stmt->execute();
56
57	$stmt = $db->query('SELECT * FROM test');
58	var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
59
60}
61
62
63/*
64// This is beyond the control of the driver... - the driver never gets in touch with bound values
65print "Emulated Prepared Statements\n";
66$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
67bug_44707($db);
68*/
69
70print "Native Prepared Statements\n";
71$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
72bug_44707($db);
73
74print "done!";
75?>
76--EXPECTF--
77Native Prepared Statements
78bool(false)
79bool(false)
80bool(false)
81array(0) {
82}
83array(1) {
84  [0]=>
85  array(2) {
86    [%u|b%"id"]=>
87    %unicode|string%(1) "1"
88    [%u|b%"mybool"]=>
89    %unicode|string%(1) "0"
90  }
91}
92done!
93