Value returned in SQLITE3 query with PHP is not what expected

Asked

Viewed 44 times

-3

Hello, good afternoon, I’m trying to select a Sqlite3 bank that sent me information, however the result that is returned to me is 0.

Here’s where I want the result:

inserir a descrição da imagem aqui

This is my code:

<?php
$db = new PDO('sqlite:C:\Users\GRUPO\Desktop\dashboard\KISMET-20200423-21-06-02-1.kismet') or die("Erro ao abrir a base");
$sql = 'SELECT COUNT(*) from devices';
$resultado = $db->exec($sql);
?>

<div class="w3-quarter">
  <div class="w3-container w3-red w3-padding-16">
    <div class="w3-left"><i class="fa fa-comment w3-xxxlarge"></i></div>
    <div class="w3-right">
      <h3><?php echo $resultado ?></h3>
    </div>
    <div class="w3-clear"></div>
    <h4>Devices Captados</h4>
  </div>
</div>

The bank returns this:

inserir a descrição da imagem aqui

The bank has no server, user or password, so I believe the connection to the bank is correct... Can anyone help me where I am missing? Thank you very much...

1 answer

0


I was able to solve after new searches and reading of the manual, I was able to get the result I expected using the fetchColumn() parameter that returns the first line :

<?php

$pdo = new PDO('sqlite:C:\Users\GRUPO\Desktop\dashboard\KISMET-20200423-21-06-02-1.kismet') or die("Erro ao abrir a base");

$nRows = $pdo->query('SELECT count(*) from DEVICES')->fetchColumn(); 

?>
    <div>
      <h3><?php echo $nRows ?></h3>
    </div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.