Advertisement
Nitorita

Basic PHP to SQLite Example

Jan 22nd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. <?php
  2. class MyDB extends SQLite3
  3. {
  4. function __construct()
  5. {
  6. $this->open('pathtodatabase');
  7. }
  8. }
  9. $db = new MyDB();
  10. if(!$db){
  11. echo $db->lastErrorMsg();
  12. } else {
  13. echo "Opened database successfully\n";
  14. }
  15.  
  16. $sql =<<<EOF
  17. INSERT INTO test_table (Name,AGE,location,description)
  18. VALUES ('Joe Smith', '29', 'New York', 'IT Technician');
  19.  
  20. EOF;
  21.  
  22. $ret = $db->exec($sql);
  23. if(!$ret){
  24. echo $db->lastErrorMsg();
  25. } else {
  26. echo "Records created successfully\n";
  27. }
  28. $db->close();
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement