WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 11669
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  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;
    }
   
}
?>



SQLite PHP Database Wrapper
Categories : PHP, PHP Classes, Databases, SQLite, Beginner Guides
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
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
This is a class with functions that are taken from simple SQL statements. I made it to have an easier connection between PHP3 and DBase files.
Categories : General SQL, PHP, PHP Classes, Databases
PHP Object Example of the Perl DBI with MySQL
Categories : PHP, PHP Classes, MySQL, Databases, Perl
TableMaint: class to help in the updating of data stored in database tables
Categories : PHP, PHP Classes, Databases
DBE - Database Expander: Edit PostgreSQL individual database tables online via your Web browser!
Categories : PostgreSQL, Complete Programs, Databases, PHP Classes, PHP
Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP.
Categories : PHP Classes, Databases, PHP, MySQL, InnoDB
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
Recordset Class like ADO Recordset (plus DataBase Splitting feature) using ODBC functions
Categories : PHP Classes, ODBC, Databases, PHP
MySQL Connection/Query Class
Categories : Databases, MySQL, PHP, PHP Classes
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes