title: False Positive in Sqlite3 Query Result
body: <p>I have a server with a Sqlite3 DB, and a client PC.</p>
  
  <p>If send a database query via ajax, I receive a true result on the query result, if the query has been done.</p>
  
  <p>My problem is: if I turn off my server while doing the DB queries, I can receive a FALSE POSITIVE, because the query is done but not fixed in the hard disk memory!</p>
  
  <p><strong>Example:</strong></p>
  
  <p><strong>Via ajax:</strong></p>
  
  <pre><code>var testo_query='INSERT INTO comanda terminale,perc_iva,id,cod_articolo,ordinamento,peso_ums,ultima_portata,numero_conto,nodo,cat_variante,dest_stampa,portata,desc_art,quantita,prezzo_un,categoria,ntav_comanda,operatore,tipo_record,stato_record,                                     prog_inser,posizione) VALUES ("null","22","DAV_20160629110600158","151","00","","","1","006","1","51","4","TARTUFO NOCCIOLA","1","5.00",
  
  var dbtype='sqlite';
  
  var dbname='provaINTELLINET.sqlite';
                                      "0","A5","DAVIDE","CORPO","ATTIVO","6","CONTO");';
  
  $.ajax({
                  type: "POST",
                  async: true,
                  url: comanda.url_server + 'classi_php/db_realtime_cassa.lib.php',
                  data: {
                      type: dbtype,
                      db_name: dbname,
                      query: testo_query
                  },
                  dataType: "json",
                  timeout: 10000,
  
                  success: function (dati) {
  
                      console.log("QUERY_CASSA_SUCCESS", dati);
  
                      //I RECEIVE A "TRUE" RESULT HERE
  
  
                      }
  
                  }
  
              });`
  </code></pre>
  
  <p>That's the server side:</p>
  
  <pre><code>&lt;?php
  
  //header('Access-Control-Allow-Origin: *');
  
  // IMPORTANTE !!
  //Se non faccio così, ai warning mi da error e ripete due volte la sincronia
  error_reporting(0);
  
  $sql = $_POST['query'];
  
  //MYSQL
  @$host = $_REQUEST['db_host'];
  @$user = $_REQUEST['db_user'];
  @$paas = $_REQUEST['db_pass'];
  
  $db_name = $_REQUEST['db_name'];
  $db_type = $_REQUEST['type'];
  
  $prefix = '../';
  
  $db2 = null;
  
  if ($db_type === 'mysql') {
      $db2 = new mysqli($host, $user, $pass, $db_name);
  } else {
      $db2 = new SQLite3($prefix . $db_name);
  }
  
  $result = false;
  
  $i = 0;
  while ($result === false &amp;&amp; $i &lt; 10) {
  
      $ms = "0." . rand(6, 9);
      sleep($ms);
      $result = $db2-&gt;query($sql);
  
      if ($result !== false) {
          $risultato_booleano = "true";
          break;
      }
  
      $risultato_booleano = "false";
      $i++;
  }
  
  if (strpos(strtolower($sql), 'select') === false) {
      $db2-&gt;close();
  } else {
      if ($db_type === 'mysql') {
          for ($i = 1; $riga = $result-&gt;fetch_assoc(); $i++) {
              $prodotti[$i] = $riga;
          }
      } else {
          for ($i = 1; $riga = $result-&gt;fetchArray(SQLITE3_ASSOC); $i++) {
              $prodotti[$i] = $riga;
          }
      }
  }
  $db2-&gt;close();
  
  
  if (@json_encode($prodotti) !== null &amp;&amp; @json_encode($prodotti) !== 'null') {
      echo json_encode($prodotti);
  } else {
      echo $risultato_booleano;
  }
  </code></pre>
  
  <p>Why?</p>