Bug #70170 [Com]: mysql bit column always fetches as empty string
| From: | pletnev dot rusalex at gmail dot com | Date: | Fri, 31 Jul 2015 04:43:21 +0000 |
| Subject: | Bug #70170 [Com]: mysql bit column always fetches as empty string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-194848@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70170&edit=1
ID: 70170
Comment by: pletnev dot rusalex at gmail dot com
Reported by: pletnev dot rusalex at gmail dot com
Summary: mysql bit column always fetches as empty string
Status: Not a bug
Type: Bug
Package: PDO MySQL
Operating System: debian
PHP Version: 5.6.11
Block user comment: N
Private report: N
New Comment:
So ok. It's not printable. But why mysqli then cast it into strings "0" and
"1" ?
If you use mysqli functions in a given script, the result will be "0" and "1"
respectively.
Suppose there must be something conventional behavior. Or it must be documented.
Previous Comments:
------------------------------------------------------------------------
[2015-07-30 21:18:47] requinix@php.net
As the output shows,
> string(1) ""
the string is not actually empty: it contains \x00 or \x01, which isn't printable.
@cmb linked another bug which is about changing that value to something better.
------------------------------------------------------------------------
[2015-07-30 20:22:25] cmb@php.net
Related to bug #70132.
------------------------------------------------------------------------
[2015-07-30 19:00:29] pletnev dot rusalex at gmail dot com
$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);
------------------------------------------------------------------------
[2015-07-30 18:50:32] 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) ""
}
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70170&edit=1