0
SELECT
CAST(REPLACE(CAST(DsXML as Nvarchar(Max)),' xmlns="http://www.portalfiscal.inf.br/nfe"','') as xml).value('(/nfeProc/NFe/infNFe/transp/vol/qVol/node())[1]', 'int') as [qVol]
FROM SPDNFE
WHERE CdIdNFe = 'NFe13161203976141000132550030000435291400513027'
When by this SQL query inside a php script, returns me the following error.
Parse error: syntax error, unexpected 'xmlns' (T_STRING)
How it is in PHP.
public function teste($teste) {
$sql = 'SELECT
CAST(REPLACE(CAST(DsXML as Nvarchar(Max)),' xmlns="http://www.portalfiscal.inf.br/nfe"','') as xml).value('(/nfeProc/NFe/infNFe/transp/vol/qVol/node())[1]', 'int') as [qVol]
FROM SPDNFE
WHERE CdIdNFe = '$teste'';
$results = array();
$stmt = $this->conn->prepare($sql);
$stmt->execute();
if ($stmt) {
while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$info = new Model();
$info->getQVol($row->qVol);
$results[] = $info;
}
}
return $results;
}
Have you tried taking this space between ' xmlns...'?
– Marco Garcia
Yes, but it’s part of the replace.
– KevinF
Test this way, please:
'SELECT
 CAST(REPLACE(CAST(DsXML as Nvarchar(Max)), " xmlns='http://www.portalfiscal.inf.br/nfe'","") as xml).value("(/nfeProc/NFe/infNFe/transp/vol/qVol/node())[1]", "int") as [qVol]
 FROM SPDNFE
 WHERE CdIdNFe = "'.$teste.'"'
– Marco Garcia