Search code examples
phpsqlsymfony1symfony-1.4

How to insert new line using doctrine_query symfony?


I have to use this :

 $deleted = Doctrine_Query::create()
  ->delete()
  ->from('orders')
  ->andWhere('user_id = "'.$_REQUEST["user_id"].'"')
  ->execute();

to delete a line from SQL in symfony, but how can I create a new line with this rows:

id|user_id|order_date|order_type|order_end_date|aktiv|fiz_meth

the name of table is: orders

How can I do that?


Solution

  • You should create a new order using this kind of code:

    $orders = new Orders();
    $orders->set('id', $id); // maybe you don't need this line, if `id` is the primary key
    $orders->set('user_id', $user_id);
    $orders->set('order_date', $order_date);
    $orders->set('order_type', $order_type);
    $orders->set('order_end_date', $order_end_date);
    $orders->set('aktiv', $aktiv);
    $orders->set('fiz_meth', $fiz_meth);
    $orders->save();
    

    Be sure to replace variable name for each column.

    You will find an other example on the second code bloc in the official doc.