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));
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
)
Maybe check your returns and see if an error occurred?
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
}
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%"));