2010-07-09 20 views
7

Da questo codice:Redbean O/RM memorizza "date" come 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); 

ottengo questo 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'); 

c'è un modo speciale per utilizzare date con redbean?

risposta

1

È possibile utilizzare time() o modificare il tipo di colonna dopo aver bloccato il DB.

+0

ma verrà memorizzato come numero intero e sarà più difficile rendere SQL basato sul confronto delle date. – Sirber

4

Sembra che tu debba essere molto specifico nel formato per una colonna datetime. Ad esempio, il codice seguente dovrebbe fornire una colonna di data/ora:

$mysqldate = date("Y-m-d", $your_date); // for date column
O
$mysqldatetime = date("Y-m-d H:i:s", $your_date_time); // for datetime column

particolare, "Ymd" per la data, e "Ymd H: i: s" per datetime, sono i formati che RedBean sta cercando.

Problemi correlati