Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //opens connection
- class MyDB extends SQLite3 {
- function __construct() {
- $this->open('db/crud_data.db');
- }
- }
- //outputs error or success
- $db = new MyDB();
- if(!$db) {
- echo $db->lastErrorMsg();
- } else {
- echo "Opened database successfully\n";
- }
- //SELECT all from TABLE
- $sql =<<<EOF
- SELECT * from COMPANY;
- EOF;
- //Executes query
- $ret = $db->exec($sql);
- //Outputs all VALUES from TABLE
- while($row = $ret->fetchArray(SQLITE3_ASSOC) ) {
- echo "ID = ". $row['ID'] . "\n";
- echo "NAME = ". $row['NAME'] ."\n";
- echo "ADDRESS = ". $row['ADDRESS'] ."\n";
- echo "SALARY = ".$row['SALARY'] ."\n\n";
- }
- echo "Operation done successfully\n";
- //Closes connection
- $db->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement