Segue o código:
$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>
Ta me retornando:
Fatal error: Call to a member function fetch() on a non-object in G:\php\sistemas\relatorios\principal.php on line 411
A linha 411 é :
while ($row = $select->fetch(PDO::FETCH_ASSOC)) {
Se eu executar a consulta no sql server ela roda normalmente, e se eu escultar alguma outra consulta no php também vai, é somente nessa que esta dando esse erro.
print_r($conexao->errorInfo());
query()
apenas uma consulta por motivos de segurança. Tem altos drops, creates e selects