codeigniter and odbc connections


codeigniter and odbc connections

我不明白CodeIgniter为什么用括号括住我的表名。当我为MS SQL使用CodeIgniter的ODBC驱动程序时,它显示了以下错误,但它使用MySql驱动程序可以完美地工作。如何阻止此错误的发生?

A Database Error Occurred
Error Number: 37000
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ')'.
SELECT * FROM (ci_sessions) WHERE session_id = '3ad914bb5f5728e8ac69ad1db8fc9841' AND user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2'
Filename: D:'wamp'www'IVR_Panel'system'database'DB_driver.php
Line Number: 330

我还尝试在SQLServer2005中执行相同的查询,该查询在没有括号的情况下运行,但仍然存在错误。我使用活动记录,所以我可以很容易地在ODBC和MySQL驱动程序之间切换。在哪里可以修改CodeIgniter以删除括号?

这实际上是CodeIgniter中的一个错误。在ODBC驱动程序(/system/database/drivers/ODBC/driver.php)中,当您选择一个表时,它使用以下方法:

function _from_tables($tables)
{
    if ( ! is_array($tables))
    {
        $tables = array($tables);
    }
    return '('.implode(', ', $tables).')';
}

它试图将多个表选择组合在一起以强制运算符优先级,如果您使用多个表,这应该可以正常工作,但对于一个表,它仍然试图对其进行分组,这会导致出现错误。

不幸的是,我认为不可能扩展这些驱动程序文件,因此您可能不得不编辑核心文件本身。请注意这一点,以防将来需要更新CodeIgniter,您将不得不将方法更改为以下内容:

function _from_tables($tables)
{
    if ( ! is_array($tables))
    {
        return strstr($tables, ',') ? '('.$tables.')' : $tables;
    }
    else
    {
        return count($tables) > 1 ? '('.implode(', ', $tables).')' : end($tables);
    }
}