how to read sqlite file in php

Solutions on MaxInterview for how to read sqlite file in php by the best coders in the world

showing results for - "how to read sqlite file in php"
Alex
19 Mar 2020
1<?php
2   class MyDB extends SQLite3 {
3      function __construct() {
4         $this->open('test.db');
5      }
6   }
7   $db = new MyDB();
8   if(!$db) {
9      echo $db->lastErrorMsg();
10   } else {
11      echo "Opened database successfully\n";
12   }
13?>
Riccardo
01 Jul 2016
1<?php
2   class MyDB extends SQLite3 {
3      function __construct() {
4         $this->open('test.db');
5      }
6   }
7   $db = new MyDB();
8   if(!$db) {
9      echo $db->lastErrorMsg();
10   } else {
11      echo "Opened database successfully\n";
12   }
13
14   $sql =<<<EOF
15      CREATE TABLE COMPANY
16      (ID INT PRIMARY KEY     NOT NULL,
17      NAME           TEXT    NOT NULL,
18      AGE            INT     NOT NULL,
19      ADDRESS        CHAR(50),
20      SALARY         REAL);
21EOF;
22
23   $ret = $db->exec($sql);
24   if(!$ret){
25      echo $db->lastErrorMsg();
26   } else {
27      echo "Table created successfully\n";
28   }
29   $db->close();
30?>