|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-07-30 18:50 UTC] pletnev dot rusalex at gmail dot com
Description:
------------
mysql bit column when there are values b'0' and b'1' fetched by PDO as empty strings ""
Test script:
---------------
<?php
/**
DROP TABLE IF EXISTS `bit_values` CASCADE;
CREATE TABLE `bit_values` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`val` bit(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `bit_values` (id, val) VALUES (1, b'0'), (2, b'1');
*/
$pdo = new PDO(
'mysql:host=localhost;dbname=dbname',
'',
''
);
$sth = $pdo->prepare("SELECT * FROM bit_values");
$sth->execute();
$r = $sth->fetchAll(PDO::FETCH_ASSOC);
echo '<pre>'; var_dump($r); echo '</pre>'; die();
Expected result:
----------------
array(2) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "0"
}
[1]=>
array(2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "1"
}
}
Actual result:
--------------
array(2) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) ""
}
[1]=>
array(2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) ""
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
$link = mysql_connect('localhost', '', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db('yiitest', $link) or die('Could not select database.'); $res = mysql_query("SELECT id, val FROM bit_values", $link ); while($row = mysql_fetch_assoc($res)) { var_dump($row); } mysql_close($link);