2
Good morning,
someone with experience in PHP and microsoft sqlsrv drive ?
I found it difficult to display data from a Procedure in SQL SERVER with the "Microsoft sqlsrv driver".
Something strange is happening that does not generate any return.
What may be speaking or wrong in the code please.
$serverName = "SRVSQLDEALER\XXX";
$connectionInfo = array( "Database"=>"DB", "UID"=>"USER", "PWD"=>"KEY");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if ( $conn ){
$var1 = '3610';
$var2 = '2020-10-29';
$procedure_params = array(
array(&$myparams['CodigoEmpresa'], SQLSRV_PARAM_OUT),
array(&$myparams['DataReferencia'], SQLSRV_PARAM_OUT)
);
$sql = "EXECUTE dbRedeMineira.dbo.whCRLDocumentosReceber @CodigoEmpresa = ?, @DataReferencia = ? " ;
$stmt = sqlsrv_query($conn,$sql,array($var1, $var2));
echo $conn."<br />";
echo $sql."<br />";
echo $stmt."<br /><br />";
$numFields = sqlsrv_num_fields( $stmt );
$numListen = sqlsrv_num_rows( $stmt );
$numAfect = sqlsrv_rows_affected( $stmt );
echo "Total de linhas > ".$numListen." .... Total de colunas > ".$numFields." .... Total afetado > ".$numAfect."<br /><br /><br />";
if (!sqlsrv_execute($stmt)) {
echo "Your code is fail!";
die;
}
if ($stmt = sqlsrv_prepare($conn, $sql)) {
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
echo $row['DataReferencia']."<br />";
}
} else {
echo "Statement could not be prepared.\n";
die(print_r(sqlsrv_errors(), true));
}
Since it is displaying a normal query, it returns all correct values.
$stmt =sqlsrv_query($conn,"SELECT * FROM usuario");
while( $row = sqlsrv_fetch_array($stmt)){
echo $row['login']."<br>";
}
Perfect, got it so thank you.
– TXN Tecnologia