MS SQL通过PHP选择二进制字段的位置

MS SQL通过PHP选择二进制字段的位置,php,sql-server,Php,Sql Server,在sql server 2016中,我有一些表。 其中之一是: CREATE TABLE [dbo].[_Reference31]( [_IDRRef] [binary](16) NOT NULL, [_Code] [nchar](9) NOT NULL, [_Fld527RRef] [binary](16) NULL) 另一个是: CREATE TABLE [dbo].[_Document8755]( [_IDRRef] [binary](16) NOT NULL, [_Nu

在sql server 2016中,我有一些表。 其中之一是:

CREATE TABLE [dbo].[_Reference31](
[_IDRRef] [binary](16) NOT NULL,
[_Code] [nchar](9) NOT NULL,
[_Fld527RRef] [binary](16) NULL)
另一个是:

CREATE TABLE [dbo].[_Document8755](
    [_IDRRef] [binary](16) NOT NULL,
    [_Number] [nchar](9) NOT NULL,
    [_Fld8997RRef] [binary](16) NOT NULL,
    [_Fld8999] [datetime] NOT NULL,
    [_Fld9000] [datetime] NOT NULL)
PHP代码如下所示:

$data=array();
$STH = $DBHMS->prepare("SELECT _Fld534, _IDRRef AS id, _Code FROM _Reference31");
$STH->execute();
$STH->setFetchMode(PDO::FETCH_ASSOC);
while($row=$STH->fetch()){
    $STH2 = $DBHMS->prepare("SELECT _IDRRef, _Number, _Fld8999, _FLd9000 FROM _Document8755 WHERE _Fld8997RRef=:id");
    $STH2->bindParam(':id',  $row['id'], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
    $STH2->execute();
    $STH2->setFetchMode(PDO::FETCH_ASSOC);
    $row['total_agreements']=$STH2->rowCount();
        while($row2=$STH2->fetch()){
            array_push($row['agreements'],$row2);
        }
        array_push($data,$row);
}
echo(json_encode($data));
问题是,total_agreements始终为零,但当我在Management Studio中手动运行第二个查询时,它可以工作

$STH2->bindParam(':id', hex2bin($row['id']), PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);

works

请在phpmyadmin中筛选表格。你能解释一下为什么是二进制字段以及它的用途吗?虽然这段代码可以回答这个问题,但提供关于它如何和/或为什么解决这个问题的附加上下文将提高答案的长期价值。