本文介绍了准备的PDO语句和MS SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我终于让CentOS盒子与网络上的MS SQL盒子对话,但是现在我在运行准备好的PDO语句时遇到了问题.如果我从末尾删除:desc并放入变量名称或单词本身,则下面的语句有效. MS SQL是否不喜欢这类语句?还是我只是缺少一些东西?
I finally got my CentOS box talking to our MS SQL box on the network, but now I'm having an issue running a prepared PDO statement to it. The below statement works if I remove the :desc from the end and put in the variable name or the word itself. Does MS SQL not like these sort of statements or am I just missing something?
$cn = "AARONS";
$result = $pdo->prepare("SELECT * from CommonNameAddress where CommonName = :desc");
$result->execute(array(':desc' => $cn));
编辑
实施一些错误检查后,返回的错误是:
edit
After implementing some error checking, the error returned is:
Array (
[0] => 22001
[1] => 0
[2] => [Microsoft][ODBC Driver 11 for SQL Server]String data, right truncation (SQLExecute[0] at /builddir/build/BUILD/php-5.3.3/ext/pdo_odbc/odbc_stmt.c:254)
[3] => 22001
)
推荐答案
最终在WHERE
部分后需要一个like
而不是=
:
Ended up needing a like
instead of =
after the WHERE
part:
$result = $pdo->prepare("SELECT * from CommonNameAddress where CommonName like :name");
$result->execute(array(':name' => "%$cn%"));
这篇关于准备的PDO语句和MS SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!