WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP5 SQLite Abstraction class
Categories : PHP, PHP Classes, SQLite, Databases Click here to Update Your Picture
Ben Yacoub Hatem
Date : Mar 08th 2005
Grade : 1 of 5 (graded 3 times)
Viewed : 5306
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ben Yacoub Hatem
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

This is a PHP5 SQLite abstraction class with many usefull functionnalities for database creation, triggers, db connections, queries, highlight ...

<?php

/**
* SQLite Abstraction class
*
* @package
* @author Ben Yacoub Hatem <hatem@php.net>
* @copyright Copyright (c) 2004
* @version $Id: sqlite.class.php,v 1.1 2004/11/03 13:46:49 hatemben Exp $ - 14/04/2004 17:44:55 - sqlite.class.php
* @access public
**/
class sqlite {

    var
$dbName = ""; //Name of databse
   
var $dbUser = ""; //Database user name
   
var $dbPwd = ""; //Database password
   
var $fallback_keywords = array("ABORT","AFTER","ASC","ATTACH","BEFORE","BEGIN","DEFERRED","CASCADE","CLUSTER","CONFLICT","COPY",
       
"CROSS","DATABASE","DELIMITERS","DESC","DETACH","EACH","END","EXPLAIN","FAIL","FOR","FULL",
       
"IGNORE","IMMEDIATE","INITIALLY","INNER","INSTEAD","KEY","LEFT","MATCH","NATURAL","OF","OFFSET",
       
"OUTER","PRAGMA","RAISE","REPLACE","RESTRICT","RIGHT","ROW","STATEMENT","TEMP","TEMPORARY","TRIGGER",
       
"VACUUM","VIEW");
       
    var
$normal_keywords = array("ALL","AND","AS","BETWEEN","BY","CASE","CHECK","COLLATE","COMMIT","CONSTRAINT","CREATE",
       
"DEFAULT","DEFERRABLE","DELETE","DISTINCT","DROP","ELSE","EXCEPT","FOREIGN","FROM","GLOB","GROUP",
       
"HAVING","IN","INDEX","INSERT","INTERSECT","INTO","IS","ISNULL","JOIN","LIKE","LIMIT",
       
"NOT","NOTNULL","NULL","ON","OR","ORDER","PRIMARY","REFERENCES","ROLLBACK","SELECT","SET",
       
"TABLE","THEN","TRANSACTION","UNION","UNIQUE","UPDATE","USING","VALUES","WHEN","WHERE");
   
   
/**
     * Constructor
     * @access protected
     */
   
function sqlite(){
    }
   
   
/**
     * sqlite::version()
     *
     * @return
     **/
   
function version(){
        return
"1.1";
    }
   
   
/**
     * sqlite::dbconnect()
     *
     * @param string $dbUser
     * @param string $dbPwd
     * @param string $dbName
     * @return
     **/
   
function dbconnect($dbUser="", $dbPwd="",$dbName=':memory:'){
        if (
$dbUser!="") {
           
$this->dbUser = $dbUser;
        }
        if (
$dbPwd!="") {
           
$this->dbPwd = $dbPwd;
        }
        if (
$dbName!="") {
           
$this->dbName = $dbName;
        }
       
$this->Link_ID = sqlite_open($this->dbName,0666) or die (_CONNECTION_ERROR_.sqlite_error_string()." <br><br>");
    }
   
   
/**
     * sqlite::query()
     *
     * @param $query
     * @return
     **/
   
function query($query){
       
$this->dbQryResult = sqlite_query($query,$this->Link_ID);
        return
$this->dbQryResult;
    }
   
   
/**
     * sqlite::fetch_row()
     *
     * @param string $result
     * @return
     **/
   
function fetch_row($result = "")
    {
       
$this->dbResultLine = sqlite_fetch_single($result);
        return
$this->dbResultLine;
    }

   
/**
     * sqlite::get_data()
     *
     * @param string $result
     * @return
     **/
   
function get_data($result = "")
    {
        return
$this->fetch_row($this->dbQryResult);
    }
   
   
/**
     * sqlite::fetch_array()
     *
     * @param string $result
     * @return
     **/
   
function fetch_array($result = "")
    {
       
$this->dbResultLine = @sqlite_fetch_array($result);
        return
$this->dbResultLine;
    }
   
   
/**
     * sqlite::get_db_tables()
     *
     * @return
     **/
   
function get_db_tables(){
     
$result = $this->query("select name,upper(name) from SQLITE_MASTER where type = 'table' order by 2");
       
        if (!
$result) {
            print
"Erreur : impossible de lister les tables\n";
            exit;
        }
       
        while (
$row = $this->fetch_row($result)) {
           
$Tables[] = $row;
        }
        return
$Tables;       
    }
   
   
/**
     * sqlite::get_db_triggers()
     *
     * @return
     **/
   
function get_db_triggers(){
     
$result = $this->query("select name,upper(name),sql from SQLITE_MASTER where type = 'trigger' order by 2");
       
        if (!
$result) {
            print
"Erreur : impossible de lister les tables\n";
            exit;
        }
       
        while (
$row = $this->fetch_row($result)) {
           
$Trigger[] = $row;
        }
        return
$Trigger;       
    }
   
   
/**
     * sqlite::get_trigger_infos()
     *
     * @param $triggername
     * @return
     **/
   
function get_trigger_infos($triggername){
     
$result = $this->query("SELECT * FROM SQLITE_MASTER where type = 'trigger' and name = '".$triggername."'");

       
$ray = $this->fetch_array($result);

        return
$ray[sql];
    }
   
   
/**
     * sqlite::get_table_infos()
     *
     * @param $tablename
     * @return
     **/
   
function get_table_infos($tablename){
     
$result = $this->query("SELECT type, name, tbl_name, rootpage, sql FROM SQLITE_MASTER where tbl_name = '" . $tablename . "'");

       
$ray = $this->fetch_array($result);
        return
$ray[sql];
    }
   
   
/**
     * sqlite::get_dbs()
     *
     * @param string $path
     * @return
     **/
   
function get_dbs($path = "db/"){
   
         
$d = opendir($path);
        while((
$entry = readdir($d)) != false) {
            if (
$entry!="." and $entry!=".." and ereg(".db$",$entry)) {
               
$DBS[] = $entry;
            }
        }
        return
$DBS;   
    }

   
/**
     * sqlite::createdb()
     *
     * @param $dbname
     * @param string $path
     * @return
     **/
   
function createdb($dbname , $path = "db/"){
        if (
trim($dbname)=="" or is_file($path.$dbname)) {
            return
FALSE;
        }
       
touch($path.$dbname);
       
chmod($path.$dbname,0666 );
        return
true;
    }

   
/**
     * sqlite::dropdb()
     *
     * @param $dbname
     * @param string $path
     * @return
     **/
   
function dropdb($dbname , $path = "db/"){
        if (!
$this->is_db($dbname )) {
            return
FALSE;
        }

        if(
unlink($path.$dbname)) return true;
       
        return
false;
    }
   
   
/**
     * sqlite::isdb()
     *
     * @param $dbname
     * @param string $path
     * @return
     **/
   
function is_db($dbname , $path = "db/"){
        if (
trim($dbname)=="" or trim($dbname)==".db" or !is_file($path.$dbname)) {
            return
FALSE;
        }
        return
true;
    }
   
   
/**
     * sqlite::get_db_size()
     *
     * @param $dbname
     * @param string $path
     * @return
     **/
   
function get_db_size($dbname , $path = "db/"){
        if (
trim($dbname)=="" or !is_file($path.$dbname)) {
            return
FALSE;
        }
        return
round(filesize($path.$dbname)/1024);
    }
   
   
/**
     *
     * @access public
     * @return void
     **/
   
function highlite($query){
       
$result = array_merge ($this->normal_keywords, $this->fallback_keywords);
        foreach(
$result as $v){
            if (
$v!="OR" and $v!="IS" and $v!="IN") {
               
$search[] = "/(?i)(^|[^a-z0-9\_]){1}(".strtoupper($v).")([^a-z0-9\_]|$){1}/";
               
$replace[] = "\\1<span style=\"color: blue; background-color: white; font-weight: bold;\">\\2</span>\\3";
            }
        }
       
$parsed_query = preg_replace($search,$replace , $query);
        return
$parsed_query;
    }
   
}
?>



MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
Powerful php/mysql Pagination for up to 6 URL Params
Categories : PHP, PHP Classes, Databases, MySQL, Navigation
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
Password reminder
Categories : PHP, PHP Classes, Databases, MySQL, Mail
MySQL Class to ease Database connectivity
Categories : MySQL, PHP Classes, Databases, PHP
usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Simple class to create insert and update statements. Independent of the access to the database. Makes handling complex inserts easier - especially when the table structure is liable to change.
Categories : Databases, PHP Classes, PHP
Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0.
Categories : Databases, PHP, mSQL, Databases
Use this class to connect your database transparently...
Categories : PHP Classes, Databases, PHP
Simple database class
Categories : PHP, PHP Classes, MySQL, Databases
Simple usersOnline class - keep track of how many users are online on your site
Categories : PHP, PHP Classes, Databases, MySQL
Online Automatic Class Generator for MySQL Tables
Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL
DBE - Database Expander: Edit PostgreSQL individual database tables online via your Web browser!
Categories : PostgreSQL, Complete Programs, Databases, PHP Classes, PHP
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides