1

I'm trying to debug below code:

$perishables = db_select('userpoints_txn', 'up_txn')
    ->fields('up_txn', array('txn_id', 'uid', 'points', 'remainder', 'time_stamp', 'tid', 'operation', 'description'))
    ->condition('status', 0, '=')
    ->condition('expired', 0, '=')
    ->condition('expirydate', 0, '!=')
    ->condition('expirydate', REQUEST_TIME, '<')
    ->execute();
 watchdog('userpoints', 'perishables->remainder  %perrr', array('%perrr' =>$perishables), WATCHDOG_DEBUG);

Can anyone help me how to get $perishables in the report log files?

2 Answers 2

1

Use print_r() with the $return argument set as TRUE.

example

watchdog('userpoints', 'perishables->remainder %perrr', array('%perrr' => print_r($perishables, TRUE)), WATCHDOG_DEBUG);
2
  • thank you for the answer.I replaced my watchdog statement,but still i'm not able to find result in recent log reports
    – rks
    Sep 16, 2015 at 6:41
  • My answer was based on the question, you only get results when you fetch them, as mentioned in @arpitr's answer.
    – Decipher
    Sep 16, 2015 at 12:53
2
  1. execute(): - this will not return query results to you. All it will return is database connection object and query string. See the screen shot. enter image description here

  2. In order to get query results, you need to call any of the retrieve function. For example

    fetch(); // Use the default fetch mode.

    fetchObject(); // Fetch as a stdClass object.

    fetchAssoc(); // Fetch as an associative array.

  3. Debugging queries:

    I would recommend you to use devel module and its help functions as dpm() and dpq() . They will make your debugging process a lot more faster can clean than watchdog.

  4. watchdog() - I confirm the answer by @Decipher(+1) will record the query object in database, see the scrrenshot tested with a simple query enter image description here

Might be that log is not something that you want to see, a small change to @Decipher answer if you want to see the query String

watchdog('userpoints', 'perishables->remainder %perrr', array('%perrr' => print_r($perishables->queryString, TRUE)), WATCHDOG_DEBUG);

You can definitely make it better the way you want with above mentioned tools

1
  • Agreed, it's better to use the devel module and dpm() & dpq(), you can run the query and see the results straight away without digging in the logs.
    – bloke_zero
    Sep 16, 2015 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.