How to cast field as type date (mysql)

瀏覽次數:35 次
跳到第一則未讀訊息

bill

未讀,
2014年9月1日 晚上10:04:242014/9/1
收件者:redbe...@googlegroups.com
I am using the Readbean ORM. I am trying to import some emails into a mysql table using imap. The following code imports an array from imap. One of the fields is $reply_bean->date;

                    $imap_array=$this->retrieve_message($inbox, $email); 
                    $reply_bean = R::dispense('reply');
                    $reply_bean->setMeta("buildcommand.unique" , array(array('date')));
                    $reply_bean->date("Y-m-d H:i:s");
                    $reply_bean->import($imap_array);

                    
                    try {
                        $id = R::store($reply_bean); 
                    }    catch (Exception $exc) {
                        
                        echo ' DUPLICATE';
                       
                    }      
          
The problem I'm having is that I am having trouble casting the date field as type 'date' instead it remains varchar and is sorted in lexicographical order.

How can I fix this?

gabor

未讀,
2014年9月2日 下午2:27:242014/9/2
收件者:redbe...@googlegroups.com


You can't cast,
RedBeanPHP cannot change the column after it has been created, that would cause loss of data.

cheers
Gabor

bill

未讀,
2014年9月7日 上午10:59:512014/9/7
收件者:redbe...@googlegroups.com
Gabor,

Thanks for explaining this. I am using vession 3 , and reading on  http://redbeanphp.com/extra/meta_data  . It appears to say :"Since 3.0: Meta data can be used for explicit casts. For instance if you want to store something as a POINT datatype:"

Thank you,

Bill

gabor

未讀,
2014年9月8日 下午2:19:062014/9/8
收件者:redbe...@googlegroups.com

I recommend not to use that feature.
It has been created to cover certain edge cases only (forcing string formats for certain numerical formats etc).
回覆所有人
回覆作者
轉寄
0 則新訊息