Redbean O/RM store "date" as varchar(255)?
Asked Answered
R

4

7

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?

Ramiah answered 9/7, 2010 at 13:19 Comment(0)
R
4

found this: http://groups.google.com/group/redbeanorm/browse_thread/thread/6961ac635e6886f6

The Optimizer will now convert columns with datetime values to datetimefields. If a different value is inserted the column will be reverted by OODB in fluid mode.

Ramiah answered 9/7, 2010 at 13:33 Comment(0)
S
4

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.

Selfless answered 3/4, 2012 at 17:7 Comment(0)
L
1

You can either use time() or change the column type after freezing the DB.

Looper answered 9/7, 2010 at 18:46 Comment(1)
but it will be stored as an integer, and it will be harder to make SQL based on date comparison.Ramiah
P
1

The Standard Optimizer handles DateTime columns. You can check it out here: http://redbeanphp.com/#/Plugins (almost at the end of the page)

Paleface answered 24/3, 2011 at 17:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.