Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7982627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:43:40+00:00 2026-06-04T10:43:40+00:00

I have the following code to get some records from db $criteria = new

  • 0

I have the following code to get some records from db

    $criteria = new CDbCriteria();
    $criteria->condition = 't.date BETWEEN "'.$from_date.'" AND "'.$to_date.'"';
    $criteria->with = array('order');

    $orders = ProductOrder::model()->findAll($criteria);

Is it possible to get the SQL that is used by the findAll? I know you can get it from the debug console. But I’m running the script in the background using yiic.php

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:43:41+00:00Added an answer on June 4, 2026 at 10:43 am

    You can log the executed queries in the application log and review that. Something like this in the config file:

    'components' => array(
      'db'=>array(
        'enableParamLogging' => true,
      ),
      'log'=>array(
        'class'=>'CLogRouter',
        'routes'=>array( 
          array(
            'class'=>'CFileLogRoute',
            'levels'=>'trace,log',
            'categories' => 'system.db.CDbCommand',
            'logFile' => 'db.log',
          ), 
        ),
      ),
    );
    

    In some cases (e.g. when running tests), you will also need to call Yii::app()->log->processLogs(null); at the end of the process for this to work.

    Of course, once you’re there nothing’s stopping you from writing your own log route that does something different with the logged messages, but mind that the logs are processed at the end of the request (or when you call processLogs), not every time you log something.


    By the way, you should not build queries like that, with dynamic input right in the query. Use bind variables instead:

    $criteria = new CDbCriteria();
    $criteria->condition = 't.date BETWEEN :from_date AND :to_date';
    $criteria->params = array(
      ':from_date' => $from_date,
      ':to_date' => $to_date,
    );
    $criteria->with = array('order');
    
    $orders = ProductOrder::model()->findAll($criteria);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in a view to get some of the information
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
I have a doubt i use the following piece of code get data from
I have the following code to get some data about companies: XDocument doc =
I have the following code: // GET: /PlayRoundHole/Create public ActionResult Create(int id) { DB
I have the following code to get details of a contact. data: is the
I have following code that does not work: I never get to goToFoodDetail .
I have written a following code to get just the file name without extension
I have used the following code to get the document root. $path = get_file_dir();
I have the following code : std::string Utils::get() { std::string result; result.append(1, 'x'); result.append(1,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.