<?Php-Power.it class Php-Power{ /* PHP Rules the World */
blog & news | articles | classes | resouces | old pages
   
classes
Simple Power SQLite class v0.6 :: 15-07-2003

Simple Power SQLite class is a simple class write in PHP, useful for standard operation with SQLite: database creation, connection, submit query, simple transaction mechanism, decode encode binary file, extend SQLite function, alter table, ecc ...

Tested on PHP 4.3.3 (Win XP) & PHP 5.0.0
Require SQLite extension for PHP < 5.0.0 (download)


<?php
//    ===============================
//               BINARY DATA
//    ===============================

// include the library
include_once 'SPSQLite.class.php';

// set a path for a dabase file
$path 'C:/AppServ/www/';

// create the object and connect to the database
$sqlite =& new SPSQLite($path 'test.db');

// create table
$query =<<<QRY
CREATE TABLE test(
    id INTEGER PRIMARY KEY,
    image BLOB,
    type VARCHAR(25)
);
QRY;

$sqlite->query($query);

// encode and store on database 'alan01.jpg' image
$data $sqlite->encodeBinary('./alan01.jpg');
$query "INSERT INTO test (image, type) VALUES('" $data "', 'image/jpeg');";
$sqlite->query($query);

// encode and store on database 'alan03.jpg' image
$data $sqlite->encodeBinary('./alan03.jpg');
$query "INSERT INTO test (image, type) VALUES('" $data "', 'image/jpeg');";
$sqlite->query($query);

// select from database
$query "SELECT image, type FROM test WHERE id = 2";
$sqlite->query($query);
$row $sqlite->returnRows();

// print the second image
header('Content-type: image/jpeg');
echo 
$sqlite->decodeBinary($row['image']);

// close SQLite connection
$sqlite->close();

// unset the object
unset($sqlite);

// delete the datadase file
unlink($path 'test.db');
?>
Resources
SPSQLite class
Examples:
Example 01
Example 02
Example 03
Example 04
Example 05
Example 06
Example 07
Example 08
API:
Class API
Downloads
SPSQLite-0.6.zip
SPSQLite-0.6.tar.gz

Old Release:
SPSQLite-0.5.zip
SPSQLite-0.5.tar.gz

SourceForge.net Logo
blog & news | articles | classes | resouces | old pages
/* da Alan D'Angelo un sito di creazioni PHP - Php-Power.it*/ }?>