I converted a web-based application from MySQLi to PDO, because I want to use Microsoft SQL-Server as database too. PDO works like a charm with MySQL database. Now I tried it for the first time with MS-SQL and it does not. Almost every query has to be updated. It is very frustrating.
The simple code below drives me nuts:
$ComputerGUID = "5BEC3779-B002-46BA-97C4-19158C13001F";
$SqlSelectQuery = "SELECT computermapping.PrinterGUID,
case when computerdefaultprinter.PrinterGUID IS NOT NULL then 1 else 0 end AS isDefaultPrinter
FROM computermapping
LEFT JOIN computerdefaultprinter ON computerdefaultprinter.ComputerGUID = computermapping.ComputerGUID
AND computerdefaultprinter.PrinterGUID = computermapping.PrinterGUID
WHERE computermapping.ComputerGUID = :ComputerGUID";
$SqlStatement = $pdo->prepare( $SqlSelectQuery );
$SqlStatement -> bindValue( ":ComputerGUID", $ComputerGUID, PDO::PARAM_STR );
$SqlStatement->execute();
$SelectQueryNumRows = $SqlStatement->rowCount();
IF ( $SelectQueryNumRows > 0 ) {
$Data = $SqlStatement->fetchAll(PDO::FETCH_ASSOC);
} ELSE {
echo "The query did not return a result ...";
}
It is working fine with MySQL and returns me a result.
With Microsoft SQL-Server it get NO RESULT. (The query did not return a result ...)
Running the same query in Microsoft SQL Server Management Studio is working fine too:
Monitoring the query when running the code with SQL Server Profiler shows the following: