2010-07-09 40 views
7

从这个代码:Redbean O/RM将“date”as 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与红豆一种特殊的方式?

回答

1

您可以使用的时间()或冻结DB后更改列类型。

+0

但它将作为整数存储,并且根据日期比较来制作SQL会更困难。 – Sirber 2010-07-09 18:57:50

4

看起来你需要在日期时间列的格式非常具体。例如,下面的代码应该提供的日期/时间列:

$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

具体而言, “YMD” 日期,和 “YMD H:I:s” 是日期时间,是RedBean正在寻找的格式。