使用Redbean PHP和日期的数据格式不正确-存储为VARCHAR(255) [英] Incorrect Data Format using Redbean PHP and dates - stored as VARCHAR(255)

查看:155
本文介绍了使用Redbean PHP和日期的数据格式不正确-存储为VARCHAR(255)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Redbean PHP连接到MySQL,并且date和date_deux都以varchar(255)的形式出现.
我假设默认情况下我处于流畅模式.我该如何解决该问题?

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;

更新:
我想我特别期待在3.0版之前执行此操作的正确方法? 文档尚不清楚3.0版之前的操作.

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.

推荐答案

在RedBeanPHP 3之前的版本中,您可以使用优化器: http://www.redbeanphp.com/extra/optimizer 如果可能的话,它基本上会在以后更改列.

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

您必须自己将优化器附加为侦听器.因为我已经看到人们对此感到挣扎,所以我删除了该系统,并将其替换为更原生的方法.现在,您只需分配SQL格式的日期或日期时间值,即可使用正确的数据类型创建该列.但是,如果该列已经用于存储其他数据,则该列将不会更改(这是为了保留该列中已经存在的数据).

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

这篇关于使用Redbean PHP和日期的数据格式不正确-存储为VARCHAR(255)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆