Redbean O/RM 存储“日期”作为 varchar(255)?
从这段代码中:
$toolbox = RedBean_Setup::kickstartDev("mysql:*****************");
$r = $toolbox->getRedBean();
$test = $r->dispense("test");
$test->nom = 'Test #1';
$test->date = '2010-07-08';
$test->date_deux = '08/07/2010';
$test->num = 5;
$id = $r->store( $test );
我得到了这个 SQL:
CREATE TABLE IF NOT EXISTS `test` (
`id` int(11) unsigned NOT NULL auto_increment,
`nom` varchar(255) collate utf8_unicode_ci default NULL,
`date` varchar(255) collate utf8_unicode_ci default NULL,
`num` tinyint(3) unsigned default NULL,
`date_deux` varchar(255) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
--
-- Dumping data for table `test`
--
INSERT INTO `test` (`id`, `nom`, `date`, `num`, `date_deux`) VALUES
(1, 'Test #1', '2010-07-08', NULL, NULL),
(2, 'Test #1', '2010-07-08', 5, NULL),
(3, 'Test #1', '2010-07-08', 5, '08/07/2010'),
(4, 'Test #1', '2010-07-08', 5, '08/07/2010'),
(5, 'Test #1', '2010-07-08', 5, '08/07/2010');
有没有一种特殊的方法来将 date
与 RedBean 一起使用?
From this code:
$toolbox = RedBean_Setup::kickstartDev("mysql:*****************");
$r = $toolbox->getRedBean();
$test = $r->dispense("test");
$test->nom = 'Test #1';
$test->date = '2010-07-08';
$test->date_deux = '08/07/2010';
$test->num = 5;
$id = $r->store( $test );
I get this SQL:
CREATE TABLE IF NOT EXISTS `test` (
`id` int(11) unsigned NOT NULL auto_increment,
`nom` varchar(255) collate utf8_unicode_ci default NULL,
`date` varchar(255) collate utf8_unicode_ci default NULL,
`num` tinyint(3) unsigned default NULL,
`date_deux` varchar(255) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
--
-- Dumping data for table `test`
--
INSERT INTO `test` (`id`, `nom`, `date`, `num`, `date_deux`) VALUES
(1, 'Test #1', '2010-07-08', NULL, NULL),
(2, 'Test #1', '2010-07-08', 5, NULL),
(3, 'Test #1', '2010-07-08', 5, '08/07/2010'),
(4, 'Test #1', '2010-07-08', 5, '08/07/2010'),
(5, 'Test #1', '2010-07-08', 5, '08/07/2010');
is there a special way to use date
with RedBean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
发现了这个:http://groups.google.com/group/redbeanorm/browse_thread /线程/6961ac635e6886f6
found this: http://groups.google.com/group/redbeanorm/browse_thread/thread/6961ac635e6886f6
看起来您需要非常具体地指定日期时间列的格式。例如,以下代码应提供日期/时间列:
$mysqldate = date("Ymd", $your_date); // 对于日期列
或
$mysqldatetime = date("Ymd H:i:s", $your_date_time); // 对于日期时间列
具体来说,“Ymd”表示日期,“Ymd H:i:s”表示日期时间,是 RedBean 正在寻找的格式。
Looks like you need to be very specific in the format for a datetime column. For instance, the following code should provide a date/time column:
$mysqldate = date("Y-m-d", $your_date); // for date column
OR
$mysqldatetime = date("Y-m-d H:i:s", $your_date_time); // for datetime column
Specifically, "Y-m-d" for date, and "Y-m-d H:i:s" for datetime, are the formats RedBean is looking for.
您可以使用 time() 或在冻结数据库后更改列类型。
You can either use time() or change the column type after freezing the DB.
标准优化器处理日期时间列。您可以在这里查看: http://redbeanphp.com/#/Plugins (几乎在最后页面的)
The Standard Optimizer handles DateTime columns. You can check it out here: http://redbeanphp.com/#/Plugins (almost at the end of the page)