Yii Framework Forum: problema con CreateCommand - Yii Framework Forum

Jump to content

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

problema con CreateCommand Rate Topic: -----

#1 User is offline   quarkmarino 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 11-August 10

Posted 01 April 2011 - 08:38 PM

Hola a todos, escribo por que tengo un problema con el uso de
Yii::app()->db->createCommand();


Her revisado la info aqui, y he construido el siguiente commando
$rows = Yii::app()->db->createCommand()
                ->select( array( 'SUM( `price` ) as earnings,', 'YEAR( DATE( `order`.`orderTime` ) ) as year,', 'MONTHNAME( DATE( `order`.`orderTime` ) ) as month' ) )
                ->from( array( 'tbl_order` `order`' ) )
                ->leftJoin( '`tbl_existence` `existence`', '`existence`.`orderId` = `order`.`id`' )
                ->where( 'DATE( `order`.`orderTime` ) BETWEEN DATE_SUB( DATE( NOW( ) ), INTERVAL 1 YEAR ) AND DATE( NOW( ) )' )
                ->group( array( 'YEAR( DATE( `order`.`orderTime` ) )', 'MONTH( DATE( `order`.`orderTime` ) )' ) )
                ->order( array( 'YEAR( DATE( `order`.`orderTime` ) ) ASC', 'MONTH( DATE( `order`.`orderTime` ) ) ASC' ) )
                ->queryAll();

sin embargo obtengo el siguiente error:

Missing argument 1 for CDbConnection::createCommand(), called in C:\...

hasta donde he visto no necesito pasar algun parametro a createCommand() si quiero construir el SQL encadenando metodos pero eso es lo que me manda el error, por otro lado si construyo el SQL con un array de parametros tal como
$rows = Yii::app()->db->createCommand( array(
                'select' =>  array( 'SUM( price ) as earnings,', 'YEAR( DATE( order.orderTime ) ) as year,', 'MONTHNAME( DATE( order.orderTime ) ) as month' ),
                'from' => array( 'tbl_order order' ),
                'leftJoin' => array( 'tbl_existence existence', 'existence.orderId = order.id' ),
                'where' => array( 'BETWEEN', 'DATE( order.orderTime )', array( 'DATE_SUB( DATE( NOW( ) ), INTERVAL 1 YEAR )', 'DATE( NOW( ) )' ) ),
                'group' => array( 'YEAR( DATE( order.orderTime ) )', 'MONTH( DATE( order.orderTime ) )' ),
                'order' => array( 'YEAR( DATE( order.orderTime ) ) ASC', 'MONTH( DATE( order.orderTime ) ) ASC' ),
            ) )->queryAll();
el error que me envia es:

PDO::prepare() expects parameter 1 to be string, array given

ya no se que hacer. y no encuentro casos parecidos en el foro, gracias.
0

#2 User is offline   Istrak 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 23-January 13
  • Location:Mexico

Posted 09 March 2013 - 10:36 AM

Creo q Tu Problema esta en como estas declarando los valores que les pasas a select, from, where....
Intentalo asi
$rows = Yii::app()->db->createCommand()
                ->select('SUM( `price` ) as earnings,', 'YEAR( DATE( `order`.`orderTime` ) ) as year,',...)
                ->from( 'tbl_order` `order`' ) 
                ....
                 ...



Si el uso de arreglos
Salud2
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