[英]Fetching bit field with mysql_query()
Here's my code: 这是我的代码:
$query = "SELECT Username, EmailVerified, Blocked FROM user";
$result = mysql_query($query, $link);
$row = mysql_fetch_assoc($result);
print_r($row);
Field Username
is string and EmailVerified
and Blocked
are of type bit . 字段Username
是字符串 , EmailVerified
和Blocked
是bit类型。 The line print_r($row)
displays the value of Username
field but not the other two. print_r($row)
显示Username
字段的值,但不显示其他两个字段的值。 I tried mysql_fetch_object(), mysql_fetch_row(), mysql_fetch_array() also, but same result. 我也尝试了mysql_fetch_object(),mysql_fetch_row(),mysql_fetch_array(),但结果相同。
Can't we fetch bit fields with mysql_query()? 我们不能用mysql_query()获取位字段吗?
我认为你需要将BIT字段转换为整数 - >
SELECT Username, CAST(EmailVerified AS unsigned integer) AS EmailV, CAST(Blocked AS unsigned integer) AS Block FROM User
Yes you can but they are retrieved as strings, and most likely end up being unprintable characters. 是的,你可以,但它们被检索为字符串,很可能最终成为不可打印的字符。 You can get the values as numbers like so: 您可以将值作为数字获取,如下所示:
$query = "SELECT Username, EmailVerified, Blocked FROM user";
$result = mysql_query($query, $link);
$row = mysql_fetch_assoc($result);
$row['EmailVerified'] = ord( $row['EmailVerified'] );
$row['Blocked'] = ord( $row['Blocked'] );
print_r($row);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.