PHP Classes

PHP SQLite CRUD: Manipulate table records in a SQLite database file

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 95 All time: 9,833 This week: 123Up
Version License PHP version Categories
php-crud-sqlite 1.0GNU General Publi...5PHP 5, Databases
Description 

Author

This class can manipulate table records in a SQLite database file.

It extends the SQLite3 PHP class to provide functions that can execute the basic create, read, update and delete operations on a given table.

The class functions take the SQL statement string as parameter to perform the INSERT, SELECT, UPDATE and DELETE queries. For SELECT queries, the class returns the query results in an array value.

Picture of Hassane Moussa
  Performance   Level  
Name: Hassane Moussa <contact>
Classes: 10 packages by
Country: Niger Niger
Age: 40
All time rank: 21481 in Niger Niger
Week rank: 312 Up1 in Niger Niger Equal
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Example

<?php

require_once 'SqliteCrud.php';

/***************************************************************************************
                                Using Functions of PHP SqliteCrud Class
***************************************************************************************/
   
    // Open the database connection

   
$db = new SqliteCrud();
       if(!
$db) {
          echo
$db->lastErrorMsg();
        }else {
          echo
"Opened database successfully\n"."<br/><br/>";
        }

   
// SQL Create Table
   
   
$sqlCreateTable ="
        CREATE TABLE IF NOT EXISTS USERS (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            firstname VARCHAR(30) NOT NULL,
            lastname VARCHAR(30) NOT NULL,
            email VARCHAR(50) NOT NULL,
            password VARCHAR(50) NOT NULL,
            age INT(3),
            location VARCHAR(25) DEFAULT NULL,
            date TIMESTAMP
        );
        "
;

   
// SQL INSERT INTO Table

   
$sqlInsert ="
        INSERT INTO USERS (firstname,lastname,email,password,age,location,date)
        VALUES ('Toto', 'TITI', 'toto@sqlite.com', '123456', '25', 'Niamey-Niger', '"
.date("Y-m-d H:i:s")."');
   
        INSERT INTO USERS (firstname,lastname,email,password,age,location,date)
        VALUES ('Alice', 'BOB', 'abob@sqlite.com', '123450', '30', 'Abuja-Nigeria', '"
.date("Y-m-d H:i:s")."');
        "
;
       
   
// SQL UPDATE

   
$sqlUpdate ="
        UPDATE USERS set password = '123456789' where email='toto@sqlite.com';
        "
;
       
   
// SQL SELECT

   
$sqlSelect ="
        SELECT * from USERS;
        "
;
       
   
// SQL DELETE

   
$sqlDelete ="
        DELETE from USERS WHERE email='abob@sqlite.com';
        "
;

   
/********************************************************
    * Use the main function
    * Choise the operation of CRUD you need to execute
    * CREATETABLE / INSERT / UPDATE / DELETE / SELECT for Default
    * @Return Boolean (true or false) For CREATETABLE / INSERT / UPDATE / DELETE Operations
    * @Return Array for SELECT Operation.
    *********************************************************/
   
    // $operation = $db->switchOperationsCrud("CREATETABLE",$sqlCreateTable); // Example of create table
    // $operation = $db->switchOperationsCrud("INSERT",$sqlInsert); // Example of Insert operation
    // $operation = $db->switchOperationsCrud("UPDATE",$sqlUpdate); // Example of Update operation
    // $operation = $db->switchOperationsCrud("DELETE",$sqlDelete); // Example of Delete operation
   
   
$operation = $db->switchOperationsCrud("",$sqlSelect); // Example of Select operation
   
if(!$operation) {
      echo
$db->lastErrorMsg();
    }else {
     
var_dump($operation);
    }
   
   
?>


Details

php-crud-sqlite

A simple class PHP CRUD SQLITE. This class use PHP CRUD (Create, Read, Update, Delete) Application using OOP (Object Oriented Programming) and SQLITE. Before used this class, below the prerequises : The sqlite3 extension must be enable. PHP 5 or newer @Author : Hassane Moussa @From Africa / Niamey-Niger @License GPL


Screenshots  
  • screenshotSelectOperationSQLITE.PNG
  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file SqliteCrud.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:95
This week:0
All time:9,833
This week:123Up
User Comments (1)