Stuff()函数返回PHP中的PDOException错误

时间:2017-08-16 06:59:18

标签: php sql-server pdo error-handling

我在MS SQL中有这段代码。它在MSSQL上工作正常但是当我尝试将它放在PHP中的API中时,它会返回PDOException错误。可能是什么问题,我将如何解决这个问题?请帮帮我。

SELECT
     cast(user_id as varchar(255)) AS member_id,skincareproductbarcode.barcode, skincareproduct.SCP_id, skincabinet.beautybox_id,  
        skincabinet.skpid, skincareproduct.photos, skincabinet.create_date
           , serial = STUFF((
          SELECT ',' + mirrorprofile.serial_number
          FROM skincabinet full join membermirrorprofile on 
membermirrorprofile.member_id = skincabinet.user_id full join mirrorprofile on mirrorprofile.mirror_id = membermirrorprofile.mirror_id
       where skincareproduct.scp_id = skincabinet.skpid   FOR XML PATH(''), TYPE).value('.', 'VARCHAR(MAX)'), 1, 1, '')
from skincabinet join skincareproduct on skincareproduct.scp_id = skincabinet.skpid 
         full join skincareproductbarcode on skincabinet.skpid = skincareproductbarcode.scp_id
     where skincareproduct.approval_flag = 'N' and skincareproduct.photos != '' 
             and substring(photos,52,3) = 'scp' order by skincareproduct.scp_id desc

错误会像这样返回

 General error: 1934 General SQL Server error: Check messages from the SQL Server [1934] (severity 16) [(null)]

我的PHP代码就像这样

if($code == 'un'){

        $listData = array();

        $stmt = $dbRemote->prepare(
        "SELECT
     cast(user_id as varchar(255)) AS member_id,skincareproductbarcode.barcode, skincareproduct.SCP_id, skincabinet.beautybox_id,  
        skincabinet.skpid, skincareproduct.photos, skincabinet.create_date
           , serial = STUFF((
          SELECT ',' + mirrorprofile.serial_number
          FROM skincabinet full join membermirrorprofile on 
membermirrorprofile.member_id = skincabinet.user_id full join mirrorprofile on mirrorprofile.mirror_id = membermirrorprofile.mirror_id
       where skincareproduct.scp_id = skincabinet.skpid   FOR XML PATH(''), TYPE).value('.', 'VARCHAR(MAX)'), 1, 1, '')
from skincabinet join skincareproduct on skincareproduct.scp_id = skincabinet.skpid 
         full join skincareproductbarcode on skincabinet.skpid = skincareproductbarcode.scp_id
     where skincareproduct.approval_flag = 'N'  order by skincareproduct.scp_id desc

    "

        );

        $stmt->execute();
        $res = $stmt->fetchAll(PDO::FETCH_ASSOC);
        foreach ($res as $row){
            $listData[] = array(

                    "SCP_id"    => $row['SCP_id'],
                    "barcode" => $row['barcode'],
                    "beautybox_id" => $row['beautybox_id'],
                    "skpid" => $row['skpid'],
                    "member_id" => $row['member_id'],
                    "photos"        => $row['photos'],
                    "time"      => $row['create_date'],
                    "SN" => $row['serial']

            );
        }
        echo json_encode($listData);
    }

0 个答案:

没有答案