SQLite Forum

Opening a database without creating a new one and Error logging
Login
Hi. I am new to PHP.
I am using this function to open a database and delete an entry, however I don't want to create new db if it doesn't exist. In that case I'd like to have an error returned to the HTML page.

Problem is that neither 

       echo "Unable to open database\n";
nor 
       echo "entry deleted\n";

 show on the browser's console on the webpage. I am using Safari on Mac.

Also the alert does not pop up although the entry is successfully deleted.

I want to have full control of the success / no success of the operation, so that this info can be fed back to the HTML page and other methods can be triggered accordingly.

Any help would be appreciated! Thanks 


<?php
   class MyDB extends SQLite3
   {
      function __construct()
      {
         $this->open('myDb.db');
      }
   }
   $db = new MyDB();
   if(!$db)
   {
       echo "Unable to open database";

   } else {
      echo "Opened database successfully\n";
       
       $Id = $_GET['Id'];
       $db->exec("DELETE FROM myDb.db WHERE entryId=\"$Id\"");
       $db->close();
      
       echo "entry deleted\n";
       alert("entry deleted");
   }
   
?>