Incorrect Data Format using Redbean PHP and dates - stored as VARCHAR(255)

家住魔仙堡 提交于 2019-12-13 08:27:52

问题


I'm connecting to MySQL with Redbean PHP and both date and date_deux come through as varchar(255).
I assume I'm in fluid mode by default. How can I correct the problem?

require('rb.php');
R::setup('my connection info',$username, $password);
$book = R::dispense( 'book' );
$book->title = 'Boost development with RedBeanPHP';
$book->author = 'Charles Xavier'; 
$book->date = '2010-07-08';
$book->date_deux = '08/07/2010';
$id = R::store($book);
echo $id;

UPDATE:
I guess specifically I'm looking forward to the correct way to do this before version 3.0? Documentation not clear on what to do prior to version 3.0.


回答1:


In RedBeanPHP versions older than 3 you can use an optimizer: http://www.redbeanphp.com/extra/optimizer It basically changes columns afterwards if possible.

You have to attach the optimizer yourself as a listener. Because I have seen people struggle with this I removed this system and replaced it for a more native approach. You can now just assign SQL formatted date or date-time values and the column will be created using the right data type. However if the column has already been used to store other data, the column will not change (this is to preserve the data already in the column).



来源:https://stackoverflow.com/questions/8495750/incorrect-data-format-using-redbean-php-and-dates-stored-as-varchar255

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!