1

I am attempting to put together a SQL String in Joomla -> Trying to connect to a MS SQL Server instance, and I have the below syntax. I have tried to use echo $query; to display the string on screen, but the query is not displaying on screen.

What is the proper syntax using JDatabase to string this together?

$query->select('select empfirstname, emplastname, empaddress, empcity, empstate');
$query->from($db->quoteName('[HiringInfo]'));
$query->where("hiredate IS NOT NULL");
$dropdownlistDates = $db->quoteName('hiredate');
if (isset($sd) && isset($ed)) 
{
    $query->where("$dropdownlistDates >= " . $db->quote($sd), 'AND');
    $query->where("$dropdownlistDates <= " . $db->quote($ed));
}
elseif (isset($datecriteria)) 
{
    if ($datecriteria != 15 
        && $datecriteria != 30 
        && $datecriteria != 45)
    {
        return null;
    }
    $min_date = DateAdd(day, $datecriteria * -1, getdate());
    $query->where("$dropdownlistDates >= " . $db->quote($min_date), 'AND');
    $query->where("$dropdownlistDates <= " . $db->quote(getdate()));
}

1 Answers1

1

You can do it with echo($query->__toString());

If you use mysql you can see all query executed in log file, only setting a parameter in my.cnf file in the [mysqld] section:

general_log_file = /path/to/query.log

general_log = 1

Rinos
  • 636
  • 2
  • 10
  • 25