在PHP SQL语句中同时拥有和/或在哪里

时间:2017-09-13 01:03:40

标签: php html joomla joomla3.0

我连接到MSSQL服务器并且我的查询没有返回任何结果 - 如果我使用echo $sql;语句,我返回的所有内容都是Array,所以我甚至无法检查语法问题!

如何修改这种语法,以便所有3个where语句按原样执行?

    <select name="employee" id="employee"></select>
$option = array();
$option['driver'] = 'mssql';
$option['host'] = 'IP ADDRESS';
$option['user'] = 'USER';
$option['password'] = 'Pass';
$option['database'] = 'DB';
$option['prefix'] = '';
$db = JDatabase::getInstance($option);
$query = $db->getQuery(true);
$query->select($db->quotename(array('Red,Blue,Green')));
$query->from($db->quoteName('EMS'));
$datefield_name = $db->quoteName('TermDate');
$employee_name = $db->quoteName('employee');
$query->where("$datefield_name >= " . $db->quote($d1), 'AND');
$query->where("$datefield_name <= " . $db->quote($d2));
if ($employeename != 'All') {
    $query->where("$employee_name <= " . $db->quote($employee));
}
$db->setQuery($query);
echo $query;
$query = $db->loadObjectList();

1 个答案:

答案 0 :(得分:0)

我不是MSSQL的专家,但我的第一印象是,在你的where语句中,你不应该在引号中包含你的变量。而不是

$query->where("$datefield_name <= " . $db->quote($d2));

$query->where($datefield_name . " <= " . $db->quote($d2));