Use mysql functions
I need use mysql functions at some model. Ex. i have a table with 3 fields, id (int), date_access (datetime), and checksum (varchar)... but, i need to apply MD5 (mysql) to field checksum when add a new row. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Use mysql functions
class SomeModel extends AppModel { function beforeSave($options = array()) { if (isset($this-data[$this-alias]['some_field'])) { $db = ConnectionManager::getDataSource($this-useDbConfig); $this-set('checksum', $db-expression('MD5(some_field)')); } } return parent::beforeSave($options); } hth grigri On Jan 13, 4:27 pm, Shadows_Cl shadows...@gmail.com wrote: I need use mysql functions at some model. Ex. i have a table with 3 fields, id (int), date_access (datetime), and checksum (varchar)... but, i need to apply MD5 (mysql) to field checksum when add a new row. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
How to use mysql functions in field list?
Hello, i tried to use mysql function `YEAR` in fields list, but faced with some problems. That field is returned in special array, see debug output and you will understand what i am talking about. $class-bindModel( array( 'hasMany' = array('Project' = array( 'fields' = array( 'id', 'name', 'apartments_total', 'building_start', 'year( building_finnish ) as building_finnish' ); debug( $model-findAll() ); [3] = Array ( [Class_] = Array ( [id] = 6 [name] = test ) [Project] = Array ( [1] = Array ( [id] = 41 [name] = dasdas [apartments_total] = 0 [building_start] = 2008-12-31 00:00:00 [class_id] = 6 [Project] = Array How to eliminate this array ?? ( [0] = Array ( [building_finish] = 2008 ) ) ) ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---