在SQL Server Native Client 10.0中执行查询时出错

时间:2021-09-18 23:49:14

I'm recently began to use php again (last time was like 7 years ago) and some fiends recommended me to use codeigniter Framework.

我最近开始再次使用php(上次就像7年前),有些恶魔建议我使用codeigniter Framework。

i trying to connect to database server in MSSQL 2008 R2 using a the odbc driver, using x64 php version over x64 IIS. This is one of the reasons because i'm not using the php native driver provided by microsoft, the other one is because the production enviroment will be in CentOS, and btw doesn't have any sense to use that driver ....

我尝试使用odbc驱动程序连接到MSSQL 2008 R2中的数据库服务器,在x64 IIS上使用x64 php版本。这是原因之一,因为我没有使用微软提供的php本机驱动程序,另一个是因为生产环境将在CentOS中,而btw没有任何意义使用该驱动程序....

going to the point: Trying to connect to a database using active record / odbc configuration throws me this error

要点:尝试使用活动记录/ odbc配置连接到数据库会引发这个错误

A Database Error Occurred
--------------------------
Error Number: 01000
[Microsoft][SQL Server Native Client 10.0][SQL Server]Executing SQL directly; no cursor.
SELECT * FROM (WebUsers)
Filename: C:\projects\php\test\system\database\DB_driver.php
Line Number: 330

and i'm only execute a simple query to retrieve a table.

我只是执行一个简单的查询来检索表。

$query = $this->db->get('WebUsers');
return $query->result_array();

these are my connection settings:

这些是我的连接设置:

$db['default']['hostname'] = 'Driver={SQL Server Native Client 10.0};Server=localhost;Database=XXXXXXXXX;';
$db['default']['username'] = 'WWWWWW';
$db['default']['password'] = 'YYYYYY';
$db['default']['database'] = 'XXXXXXXXX';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

DOn't have any idea how to solve it

不知道如何解决它

2 个解决方案

#1


3  

I think this is an old bug in CI. You have to modify a function _form_tables() in /system/database/drivers/odbc/odbc_driver.php

我认为这是CI中的一个老错误。你必须修改/system/database/drivers/odbc/odbc_driver.php中的函数_form_tables()

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

Hope this will work.

希望这会奏效。

#2


0  

$this->db->query($sql);     

instead of above query use bellow method for execute procedure in codeigniter

而不是上面的查询使用下面的方法来执行codeigniter中的执行过程

 $this->db->simple_query($sql);

#1


3  

I think this is an old bug in CI. You have to modify a function _form_tables() in /system/database/drivers/odbc/odbc_driver.php

我认为这是CI中的一个老错误。你必须修改/system/database/drivers/odbc/odbc_driver.php中的函数_form_tables()

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

Hope this will work.

希望这会奏效。

#2


0  

$this->db->query($sql);     

instead of above query use bellow method for execute procedure in codeigniter

而不是上面的查询使用下面的方法来执行codeigniter中的执行过程

 $this->db->simple_query($sql);