PHP Classes

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

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 96 All time: 9,858 This week: 455Up
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: 21461 in Niger Niger
Week rank: 164 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 (1)  
  • screenshotSelectOperationSQLITE.PNG
  Files folder image Files (5)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:96
This week:0
All time:9,858
This week:455Up
User Comments (1)