0
I need to know how many records were entered in the query below.
public function CadastraCliente() {
$this->conn->beginTransaction();
try {
$stmt = $this->conn->prepare("
INSERT INTO SISCli (CdInscricao,DsEntidade,DsApelido,InInscricao,InCadastro,DsEndereco,NrCEP,NrInscricaoEstadual,NrCGCCPF,NrTelefone,DtCadastro,CdEmpresa,DsEMail,DsUSuarioInc,InClassificacaoFiscal,DsBairro)
SELECT
right( ('00000000' + cast(ESP353_XML.DES_NrCGCCPF as varchar)), 14) as [CdInscricao],
ESP353_XML.DES_DsEntidade AS [DsEntidade],
ESP353_XML.DES_DsApelido AS [DsApelido],
ESP353_XML.DES_InInscricao,
0 AS [InCadastro],
ESP353_XML.DES_DsEndereco AS [DsEndereco],
ESP353_XML.DES_NrCEP AS [NrCEP],
ESP353_XML.DES_NrInscricaoEstadual AS [NrInscricaoEstadual],
case when LEN(ESP353_XML.DES_NrCGCCPF) > 11
then right( ('00'+ cast(ESP353_XML.DES_NrCGCCPF as varchar)), 14)
else right( ('00000'+ cast(ESP353_XML.DES_NrCGCCPF as varchar)), 11)
end as [NrCGCCPF],
ESP353_XML.DES_NrTelefone AS [NrTelefone],
GETDATE() AS [DtCadastro],
case when SISCEP.DsUF='SP' then '4'
when SISCEP.DsUF='PR' then '3'
when SISCEP.DsUF='SC' then '12'
ELSE '1' END
as [CdEmpresa],
ESP353_XML.DES_DsEMail as [DsEMail],
'EdiXML' AS [DsUSuarioInc],
ESP353_XML.DES_InClassificacaoFiscal,
substring(ISNULL(ESP353_XML.DES_DsBairro,0),1,15) as [DES_DsBairro]
FROM ESP353_XML
LEFT JOIN SISCEP ON SISCEP.NrCep = ESP353_XML.DES_NrCEP
where not exists (select 1 from SISCli A WHERE cast(A.CdInscricao as numeric) = cast(ESP353_XML.DES_NrCGCCPF as numeric))
");
$stmt->execute();
$this->conn->commit();
} catch (Exception $e) {
$this->conn->rollback();
echo $e;
}
}
What I’ve already tried:
$stmt->execute();
$count = $stmt->rowCount();
print_r($count);
Always returns zero? what’s the problem with the code?
– rray
have you tried to make
count()
? What$stmt->rowCount();
returns ?– 13dev
Returns -1 when I give the
print_r
in the$count
– KevinF
You want the number of queries executed or the number of Updates and Inserts executed?
– Guilherme Nascimento
De update’s and Insert’s executed. How many lines have been affected, the same return it shows when running directly in sgbd.
– KevinF
@Kevin. F try to run rowCount after the commit and tell me what happened.
– Guilherme Nascimento
It keeps returning -1, after I run this function call it in the view, so I wanted to show how many were executed (in my case registered).
– KevinF