Codeigniter和odbc连接 [英] codeigniter and odbc connections

查看:65
本文介绍了Codeigniter和odbc连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I don't understand why CodeIgniter is wrapping my table name in brackets. When I use CodeIgniter's ODBC driver for MS SQL it shows the errors below, however it works perfectly using the MySql driver. How can I stop this error from occurring?

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

我也尝试过在SQL Server 2005中执行相同的查询,该查询在没有括号的情况下仍然有效,但仍然存在错误.我正在使用活动记录,因此可以在ODBC和MySQL驱动程序之间轻松切换.在哪里可以修改CodeIgniter以删除括号?

I've also tried executing the same query in SQL Server 2005 which works without the brackets but still errors with them. I am using active record so I can switch between ODBC and MySQL drivers easily. Where can I modify CodeIgniter to remove the brackets?

推荐答案

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

This is actually a bug in CodeIgniter. In the ODBC driver (/system/database/drivers/odbc/odbc_driver.php) when you select a table it uses the following method:

function _from_tables($tables)
{
    if ( ! is_array($tables))
    {
        $tables = array($tables);
    }

    return '('.implode(', ', $tables).')';
}

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

It attempts to group multiple table selections together to enforce operator precedence, this should work fine if you are using more than one table, however with one table it still tries to group it which causes the error you are getting.

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

Unfortunately, I don't believe it's possible to extend these driver files so you may have to edit the core file itself. Take note of this in case you need to update CodeIgniter in the future, you will have to change the method to something like the following:

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

这篇关于Codeigniter和odbc连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆