Yii Framework Forum: CDbCommand or CDbCommandBuilder - Yii Framework Forum

Jump to content

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

CDbCommand or CDbCommandBuilder Should I use one or other Rate Topic: -----

#1 User is offline   tuga 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 02-January 10

Posted 04 January 2010 - 12:41 PM

Hi,

First let me explain I will be fetching a lot of records from tables, I will not be using ARecord as I wont' be updating or deleting data for now. So I think I will using CDbCommand or CDbCommandBuilder to fetch the data. This is right?

I've looked at the CDbCommand and I've managed to get the results with the following code:
$connection = Yii::app()->db;
$sql = "SELECT * FROM Hotels LIMIT 10";
$command = $connection->createCommand($sql);
$data = $command->query();
$this->render('index', $data);


But I will be doing some complex queries with sorting and criteria, should I use CDbCommand or CDbCommandBuilder?
I can't seem to find much information about the CDbCommandBuilder, is there any good place to see this documentation?

Sorry if all the questions are so noob.

Thanks
0

#2 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 04 January 2010 - 05:55 PM

for direct calling queries I think the simple CDbCommand have all do you need;

another way:

$connection=new CDbConnection($dsn,$username,$password);
$connection->active=true;
After the DB connection is established, one can execute an SQL statement like the following: 
$command=$connection->createCommand($sqlStatement);
$command->execute();   // a non-query SQL statement execution
// or execute an SQL query and fetch the result set
$reader=$command->query();
// each $row is an array representing a row of data
foreach($reader as $row){
print_r($row);
}


regards
trying build code for Generate complete CRUD source code with YII... any help?
post comments here:
EXTENDING CRUD GENERATION (scaffolding)

old tentative released (module generator):
http://www.yiiframew...sion/modulegen/
0

#3 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 05 January 2010 - 03:39 AM

In my understanding CDbCommandBuilder is the "engine" that is used by AR to build its SQL statements.
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