1

I am currently debugging php code. One of the trouble is, I don't know how to print out the variable's value. Our code is constructed in Zend framework and IDE is phpstorm.

For example, for the following SQL query, how can I print out the actual sql sentence sending to database? Or, in another word, is there a way to print $query as a string to somewhere? Such as Chrome's console? Thanks for your advice.

$query = DB::table('ctre_contact AS contact')
                ->join('ctre_company AS company', 'company.id', '=', 'contact.company_id')
                ->select(
                    'contact.id',
                    'contact.first_name',
                    'contact.last_name',
                    'company.name AS company_name',
                    DB::raw("COALESCE(FIND_IN_SET(contact.id, '$program->client_admin'), 0) AS is_client_admin"),
                    DB::raw("COALESCE(FIND_IN_SET(contact.id, '$program->program_admin'), 0) AS is_program_admin"),
                    DB::raw("COALESCE(FIND_IN_SET(contact.id, '$program->user'), 0) AS is_user"),
                    DB::raw("COALESCE(FIND_IN_SET(contact.id, '$program->user_monitor_role'), 0) AS is_user_monitor")
                );

            if (!empty($where)) {
                $query->whereRaw(join(" AND ", $where));
            }
new2cpp
  • 3,311
  • 5
  • 28
  • 39

1 Answers1

1

You can do this with the __toString() function:

$sql = $query->__toString();
henrik
  • 1,558
  • 3
  • 14
  • 29