我终于让我的CentOS盒子与网络上的MS SQL盒子对话,但现在我遇到了运行准备好的PDO语句的问题。如果我从末尾删除:desc并输入变量名或单词本身,则下面的语句有效。 MS SQL不喜欢这些语句,还是我错过了什么?
$cn = "AARONS";
$result = $pdo->prepare("SELECT * from CommonNameAddress where CommonName = :desc");
$result->execute(array(':desc' => $cn));
执行一些错误检查后,返回的错误是:
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
)
答案 0 :(得分:1)
在like
部分之后,需要=
代替WHERE
:
$result = $pdo->prepare("SELECT * from CommonNameAddress where CommonName like :name");
$result->execute(array(':name' => "%$cn%"));
答案 1 :(得分:0)
也许检查您的退货并查看是否发生错误?
if( ! $result = $pdo->prepare("SELECT * from CommonNameAddress where CommonName = :desc") ) {
print_r( $pdo->errorInfo() );
} else if( !$result->execute(array(':desc' => $cn)) ) {
print_r( $result->errorInfo() );
} else {
//success
}