Yii Framework Forum: Mysql Inset Query- Null Issue - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Mysql Inset Query- Null Issue Query execution from yii doesn't inset default NULL in DB

#1 User is offline   P.A. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 21-April 12

Posted 24 December 2012 - 10:06 PM

Hi,

I am having some columns in db, which are having default value as NULL. When I execute INSERT command, from Mysql workbench/Command Line , it correctly insert 'NULL' for the columns, for which value is not present.
But when I fire same query from yii, it doesn't insert 'NULL', instead it shows blank,
Also one more issue, for DATETIME its inserting '0000-00-00 00:00:00', I want this to NULL, but I am not getting it right.
0

#2 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 25 December 2012 - 02:18 AM

View PostP.A., on 24 December 2012 - 10:06 PM, said:

Hi,

I am having some columns in db, which are having default value as NULL. When I execute INSERT command, from Mysql workbench/Command Line , it correctly insert 'NULL' for the columns, for which value is not present.
But when I fire same query from yii, it doesn't insert 'NULL', instead it shows blank,
Also one more issue, for DATETIME its inserting '0000-00-00 00:00:00', I want this to NULL, but I am not getting it right.



By default Yii check its model class attributes definition first and according to that create a query.and if you have define a datetime field as a null then for sure it will insert value as you have show above.And i guess it will work same in other frameworks too in the case of datetime field.

But if you want to assign that field as a null value then you can change it value like above.

$model->datetime='NULL';


Let it try. I hope it will work here.
CodeSutra
0

#3 User is offline   mbala 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 131
  • Joined: 21-July 12
  • Location:Chennai, Tamilnadu, India

Posted 25 December 2012 - 07:30 AM

I wrote two types of code for this
unset($model->date);

$model->date=new CDbExpression('NULL');


JUST TRY THIS
____________________
mbala
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users