【发布时间】:2013-11-07 21:01:59
【问题描述】:
我正在尝试使用 codeigniter 对一些 mysql 数据进行简单的SELECT。
//setup query
$this->db->select('personId, birthday')
->from('person')
->where('personId', $personId)
->limit(1);
//execute query
$query = $this->db->get();
//fetch result
$result = $query->row_array();
//found person
if(!empty($result)){
echo $result['birthday'];
}
}
}
birthday 字段在 mySQL 中作为 DATE 类型。 DB 中和 phpMyAdmin 中看到的值是 '1980-05-21',但上面代码中回显的值只是 '1980',只是年份。
我尝试将 mysql 类型切换为 DATETIME,但没有任何效果。
我的猜测是它与 Codeigniter 有关,甚至可能与结果中的“-”字符有关。这个问题快把我逼疯了!有人遇到过这个问题,知道如何解决吗?
【问题讨论】:
-
几乎不好意思承认答案。我对我的生产数据库而不是我的开发数据库进行了类型更改。哎呀。感谢所有的建议。有时只需要其他人的一些意见来发现你的愚蠢错误。
标签: php mysql codeigniter datetime