MSSQL 和 PHP:“传递给 sqlsrv_query 的参数无效." [英] MSSQL and PHP: "An invalid parameter was passed to sqlsrv_query."

查看:223
本文介绍了MSSQL 和 PHP:“传递给 sqlsrv_query 的参数无效."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 PHP 运行一个非常简单的 MSSQL 更新语句,但是我收到一条错误消息:*一个无效的参数被传递给 sqlsrv_query."*

I'm trying to run a very simple MSSQL update statement through PHP, but I get an error saying *"An invalid parameter was passed to sqlsrv_query."*

这是我正在使用的连接类,最相关的是查询函数:

Here's the connection class I'm using, and most relevant is the query function:

function query($query) {
    $result = sqlsrv_query($query) or die( print_r( sqlsrv_errors(), true));
}

最后,这是我用来尝试执行语句的代码:

Finally, here's the code I'm using to try to execute the statement:

$db = new mssqlClass();
$conn = $db->connect();

$SQL = "UPDATE table SET Title = 'Test' where ID = 1"
$SQL = $db->query($SQL);

如果有人有任何建议,我将不胜感激,我想这是连接类的问题,但我不确定.谢谢!

If anyone has any suggestions I'd be very grateful, I guess it's a problem with the connection class but I'm unsure. Thank you!

(edit) 在尝试编辑所有内容以便在此处发布时,我不知何故错过了声明中的位置",啊!对不起.毋庸置疑,查询没问题,复制到 SQL Server Studio 管理器后执行没有任何问题.干杯

(edit) In trying to edit everything down for the purpose of posting here, I somehow missed the 'where' from my statement, agh! Sorry. Needless to say the query is fine, and when copied into SQL Server Studio Manager executes without any issues. Cheers

推荐答案

我不喜欢回答我自己的问题,但由于我最初提出这个问题很混乱,我希望这对看到此问题的人有所帮助来自 Google.

I don't like answering my own questions, but since I made such a mess of asking this question initially I'm hoping this is helpful for anyone seeing this from Google.

与 mssql_query 不同,较新的 sqlsrv_query 函数需要将连接参数作为第一个变量传入,如下所示:

Unlike mssql_query, the newer sqlsrv_query function needs the connection paramter to be passed in as the first variable, like so:

$result = sqlsrv_query($this->connection, $query) or die( print_r( sqlsrv_errors(), true));

这篇关于MSSQL 和 PHP:“传递给 sqlsrv_query 的参数无效."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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