change table column type in redbean

58 views
Skip to first unread message

navid shokri

unread,
Jul 2, 2015, 5:42:14 AM7/2/15
to redbe...@googlegroups.com

i am using redbeanphp for database manipulation. i create a table and add a row to my database using this code :

$bean= R::dispence("esate") ; 
$bean->import(json_decode($data)) ; 
R::store($bean); 

in my $data variable i have null property such as address and when redbeanphp store this bean in database set this property type to tinyint or other type. now when i create another bean with address property my sql ignore my value and left address column null.

can redbean handle this problem and if answer is YES how ?


gabor

unread,
Jul 3, 2015, 6:10:50 PM7/3/15
to redbe...@googlegroups.com, navid...@gmail.com

Sorry for my late reply,

RedBeanPHP should be able to handle NULL values just fine, here is my code:
$bean = R::dispense('bean');
$bean
->import(json_decode('{"address":null}'));
R
::store($bean);

$bean
= R::dispense('bean');
$bean
->import(json_decode('{"address":"test"}'));
R
::store($bean);




var_dump
(R::getAll('SELECT * FROM bean'));


~                                  
result:
array(2) {
 
[0] =>
  array
(2) {
   
'id' =>
   
string(1) "1"
   
'address' =>
    NULL
 
}
 
[1] =>
  array
(2) {
   
'id' =>
   
string(1) "2"
   
'address' =>
   
string(4) "test"
 
}
}



cheers
abor
Reply all
Reply to author
Forward
0 new messages