2
Follows 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>
You’re returning to me:
Fatal error: Call to a Member Function fetch() on a non-object in G: php main reporting systems.php on line 411
The line 411 is :
while ($row = $select->fetch(PDO::FETCH_ASSOC)) {
If I run the query in sql server it runs normally, and if I listen to some other query in php will too, it is only in this one that this giving error.
Your query failed, you need to check what the error is. Make a
print_r($conexao->errorInfo());
– rray
Array ( [0] => 00000 [1] => 0 [2] => ((null)[0] at (null):0) [3] => )
– Chefe Druida
Strange that in sql server has the results
– Chefe Druida
Perhaps because sql server runs several queries, by default the
query()
only one query for security reasons. It has highDrops, creates and selects– rray
The problem is that you are dropping at the end and the message is being considered as a resultset as well. Take the "if" with the drop that will work.
– Sorack
@Sorack I’ve already removed the if and the same thing happens
– Chefe Druida
before the drop puts a line with "set nocount on";
– Sorack
Now you have modified the message: Array ( [0] => 42S02 [1] => 3701 [2] => [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the table '#Tabbeats', because it does not exist or you do not have permission. (Sqlexecute[3701] at ext pdo_odbc odbc_stmt. c:254) [3] => 42S02 )
– Chefe Druida
Try using it with two #... change from #Tabbeats to ##Tabbeats
– Sorack
You can also drop the table only at the end and take the one from the beginning and take the if too
– Sorack