Quantcast
Channel: Microsoft Drivers for PHP for SQL Server forum
Viewing all articles
Browse latest Browse all 391

SQLSTATE[07002]: [Microsoft][SQL Server Native Client 10.0]COUNT field incorrect or syntax error

$
0
0

Hi,

The problem comes from using a placeholder multiple times in a query...

I never had this with other DB systems.

Here is an example to reproduce the error :

This code finds any reservation in conflict with (:begin,:end).

$sql="
    Select * from Reservation WHERE (
                        (Hour_Begin<=:Begin and Hour_End>=:Begin) or
                        (Hour_Begin<=:Begin and Hour_End>=:End) or
                        (Hour_Begin>=:Begin and Hour_End<=:End)or
                        (Hour_Begin<=:Begin and Hour_End>=:End)
                        )";
$db= new PDO ( "sqlsrv:server=xxx;Database=xxx","xxx","xxx", array () );
$sth=$db->prepare($sql);
$sth->bindValue(':Begin','30-07-2012 08:00');
$sth->bindValue(':End','30-07-2012 17:30');
$ex=$sth->execute();
$arr = $sth->errorInfo();
print_r($arr);
$dr=$sth->fetchAll();
var_dump($dr);
exit;


Viewing all articles
Browse latest Browse all 391

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>