简体   繁体   English

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

[英]Error executing Queries in SQL Server Native Client 10.0

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. 我尝试使用odbc驱动程序连接到MSSQL 2008 R2中的数据库服务器,在x64 IIS上使用x64 php版本。 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 .... 这是原因之一,因为我没有使用微软提供的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 不知道如何解决它

I think this is an old bug in CI. 我认为这是CI中的一个老错误。 You have to modify a function _form_tables() in /system/database/drivers/odbc/odbc_driver.php 你必须修改/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. 希望这会奏效。

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 超时问题-SQL Server Native Client 10.0,TCP提供程序-错误258 - Timeout issue - SQL Server Native Client 10.0, TCP Provider - Error 258 SQL语法错误,执行几个查询时? - SQL Syntax error, when executing several queries? SQL Server 2008 R2本机客户端 - SQL Server 2008 R2 Native Client 执行 SQL 查询时出错,如果单独执行,这些查询会起作用 - Error while executing SQL queries, which work if executed separately [Microsoft] [SQL Server本机客户端11.0]共享内存提供程序:超时错误[258] - [Microsoft][SQL Server Native Client 11.0]Shared Memory Provider: Timeout error [258] …/ db.php:46中的消息“ SQLSTATE [07002]:[Microsoft] [SQL Server Native Client 11.0] COUNT字段不正确或语法错误”的“ PDOException” - 'PDOException' with message 'SQLSTATE[07002]: [Microsoft][SQL Server Native Client 11.0]COUNT field incorrect or syntax error' in …/db.php:46 从php执行时SQL Server存储过程错误 - SQL Server stored procedure error while executing from php 使用PHP在一个语句中执行多个SQL查询 - Executing multiple SQL queries in one statement with PHP [Microsoft] [SQL Server本机客户端11.0] SQL Server网络接口:连接字符串无效 - [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Connection string is not valid 无法运行查询:SQLSTATE [42000]:[Microsoft] [SQL Server Native Client 11.0] [SQL Server]')'附近的语法不正确 - Failed to run query: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ')'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM