Incorrect Data Format using Redbean PHP and dates

2019-09-17 03:53发布

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条回答
Luminary・发光体
2楼-- · 2019-09-17 03:58

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).

查看更多
登录 后发表回答