xchwarze
(Kirima Nagi)
July 4, 2013, 2:42pm
#1
hello forum!
i want to execute this query
$query = 'INSERT INTO Pedidos (OrdenCompra, Cliente, Fecha, Anulado)
VALUES (' . (int)$id . ', ' . Yii::app()->user->id . ', NOW(), 0)';
$query = Yii::app()->db->createCommand($query)->execute();
but fail
would be the right way to do?
vizrs
(Ricemafersim)
July 5, 2013, 10:11am
#2
Hello xchwarze!
Try something like this:
...
$fecha = new CDbExpression('NOW()');
$query = 'INSERT INTO Pedidos (OrdenCompra, Cliente, Fecha, Anulado)
VALUES (' . (int)$id . ', ' . Yii::app()->user->id . ', ' . $fecha . ', 0)';
$query = Yii::app()->db->createCommand($query)->execute();
...
vizrs
(Ricemafersim)
July 8, 2013, 3:49pm
#4
xchwarze:
CDbException
I don’t get it!! I have tested the code right now and works perfectly! Btw… show us your code, the full error and the database table so we can help you better.
xchwarze
(Kirima Nagi)
July 10, 2013, 2:51pm
#5
thanks RSfTDL!
I changed NOW() with GETDATE() and works!
(I forget to mention that database engine used)
Hi
You can write a insert query
$model = new Pedidos();
$model->OrdenCompra=$id;
$model->Cliente='';
$model->Fecha=Yii::app()->user->id;
$model->Anulado=date('Y-m-d');
$model->save(false)