Follow the code:
$conexao = new PDO("odbc:Driver={SQL Server};Server=127.0.0.1;Database=MASTERDB; Uid=admin;Pwd=admin123;");
$select = $conexao->query("IF Object_ID('tempDB..#TabBatidas', 'U') is not null
DROP TABLE #TabBatidas;
SET DATEFIRST 7; -- domingo
with
Consulta as (
SELECT
F.FILIAL AS FILIAL,
F.COLIGADA AS COLIGADA,
F.CHAPA AS CHAPA,
F.SECAO AS SECAO,
F.SITUACAO AS SITUACAO,
F.NOME AS NOME,
V.DATA,
DATENAME(dw,V.DATA) AS DIA,
MAX(V.SEQUENCIALBATIDA) AS BATIDA
FROM
ARELBATIDATRANSITOVIEW AS V
LEFT JOIN vwFUNC AS F ON V.CHAPA = F.CHAPA
WHERE
DATEPART(dw,V.DATA) = 1 -- domingo
AND BATIDA IS NOT NULL
AND V.DATA BETWEEN '$v_datainicio' AND '$v_datafinal'
AND V.CODCOLIGADA = 1
GROUP BY V.CHAPA,V.DATA,
F.FILIAL,F.COLIGADA,F.CHAPA,F.SECAO,F.FUNCAO,F.NOME,F.SITUACAO
)
SELECT *
into #TabBatidas
from Consulta;
CREATE clustered INDEX I1_TB on #TabBatidas (CHAPA, DATA);
SELECT
T1.CHAPA AS CHAPA,
T1.NOME AS NOME,
T1.FILIAL AS FILIAL,
T1.SECAO AS SECAO,
T1.SITUACAO AS SITUACAO,
Cast(T1.DATA as date) as [DATA 1],
Cast(T2.DATA as date) as [DATA 2],
Cast(T3.DATA as date) as [DATA 3],
'04 - TESTE DOMINGO' AS OCORRENCIA
from #TabBatidas as T1
inner join #TabBatidas as T2 on T2.CHAPA = T1.CHAPA
inner join #TabBatidas as T3 on T3.CHAPA = T1.CHAPA
where T2.DATA = DateAdd(day, +7, T1.DATA)
and T3.DATA = DateAdd(day, +14, T1.DATA);
--
IF Object_ID('tempDB..#TabBatidas', 'U') is not null
DROP TABLE #TabBatidas;
go");
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">04 - TESTE DE DOMINGO</h3>
</div>
<div class="panel-body">
<table class='datatable table table-hover table-bordered table-responsiv'>
<thead>
<tr>
<th>CHAPA</th>
<th>NOME</th>
<th>FILIAL</th>
<th>SECAO</th>
<th>SITUACAO</th>
<th>1° DOMINGO</th>
<th>2° DOMINGO</th>
<th>3° DOMINGO</th>
</tr>
</thead>
<?php
echo"<tbody>";
while ($row = $select->fetch(PDO::FETCH_ASSOC)) {
echo" <tr>";
echo"<td>".$row['CHAPA']."</td>";
echo"<td>".$row['NOME']."</td>";
echo"<td>".$row['FILIAL']."</td>";
echo"<td>".$row['SECAO']."</td>";
echo"<td>".$row['SITUACAO']."</td>";
echo"<td>".$row['DATA 1']."</td>";
echo"<td>".$row['DATA 2']."</td>";
echo"<td>".$row['DATA 3']."</td>";
echo" </tr>";
}
echo" </tbody>";
echo" </table>";
?>
</div>
</div>
Turning me back:
Fatal error: Call to a member function fetch () on a non-object in G: \ php \ systems \ reports \ main.php on line 411
Line 411 is:
while ($row = $select->fetch(PDO::FETCH_ASSOC)) {
If I run the query in sql server it runs normally, and if I enterate another query in php it will also, it is only in this one that is giving this error.