我正在使用 Wordpress 中的 WPDB 对象与 MySQL 数据库进行通信。我的数据库有一个类型为 的列bit(1)
,但是,Wordpress 不会在我的生产服务器上将它们提取为0
或1
(它们是在我的本地计算机上提取的)。
问题:
如果我有来自 Wordpress 的数据库值,我无法与0
or进行简单的比较1
:
if ($data[0]->Sold == 1) { //Always false
...
if ($data[0]->Sold == 0) { //Always false
如何检查该值是否0
为1
?
背景:
这在我的本地机器上不是问题,而只是在生产中。
我这样查询数据库:
$data = $wpdb->get_results("...");
当我var_dump()
对数据库的结果执行操作时,这是我的浏览器显示的输出:
array(1) {
[0] => object(stdClass)#261 (10) {
["SaleID"] => string(4) "1561"
["BookID"] => string(2) "45"
["MerchantID"] => string(1) "1"
["Upload"] => string(19) "2012-11-20 15:46:15"
["Sold"] => string(1) ""
["Price"] => string(1) "5"
["Condition"] => string(1) "5"
["Written"] => string(1) ""
["Comments"] => string(179) "<p>I am the first owner of this barely used book. There aren't any signs of normal wear and tear, not even any creases on the cover or any of its pages. It would pass for new.</p>"
["Expiring"] => string(19) "2013-05-20 15:46:15"
}
}
注意如何显示字符串大小Sold
,但没有关联的值。这些值应分别用和填充。Written
1
1
0
Chrome 检查器工具对这些值显示了一些非常有趣的东西:
什么是\u1
or \u0
,为什么它们不是简单的1
or 0
,所以我可以进行比较?
感谢您的时间。