PHP Classes

File: examples.php

Recommend this page to a friend!
  Classes of ZLioxygon   Minimalistic DB   examples.php   Download  
File: examples.php
Role: Example script
Content type: text/plain
Description: Examples
Class: Minimalistic DB
Database abstraction layer with minimal interface
Author: By
Last change:
Date: 11 years ago
Size: 2,433 bytes
 

Contents

Class file image Download
<?php
include_once('db.php');
/******************************************************************************
use array
/******************************************************************************/
$config = array(
       
'class' => 'mysql',
       
'host' => 'localhost',
       
'port' => '3306',
       
'sock' => false,
       
'user' => 'root',
       
'pass' => '',
       
'base' => 'test',
       
'coll' => 'utf8',
    );

try{
   
$result = db($config)->q('select * from `wordlist`');
   
print_r($result);
    echo(
"\nFields: " . db()->f());
    echo(
"\nRows: " . db()->r());
    echo(
"\nCounter: " . db()->i());
    echo(
"\nTimer: " . db()->t());
}
catch(
db_Exeption $e){
    echo(
$e->getMessage() . ' on line ' . $e->getLine() . "\n");
}
/******************************************************************************
OR use JSON-encoded string
/******************************************************************************/
$db_config = '{"class":"mysql","host":"localhost","port":"3306","sock":false,"user":"rootuser","pass":"password","base":"zlioxygon","coll":"utf8"}';

try{
   
$result = db($db_config)->q('select * from `wordlist`');
   
print_r($result);
    echo(
"\nFields: " . db()->f());
    echo(
"\nRows: " . db()->r());
    echo(
"\nCounter: " . db()->i());
    echo(
"\nTimer: " . db()->t());
}
catch(
db_Exeption $e){
    echo(
$e->getMessage() . ' on line ' . $e->getLine() . "\n");
}
/******************************************************************************
OR use JSON-encoded file
/******************************************************************************/
try{
   
$result = db('db_config.json')->q('select * from `wordlist`');
   
print_r($result);
    echo(
"\nFields: " . db()->f());
    echo(
"\nRows: " . db()->r());
    echo(
"\nCounter: " . db()->i());
    echo(
"\nTimer: " . db()->t());
}
catch(
db_Exeption $e){
    echo(
$e->getMessage() . ' on line ' . $e->getLine() . "\n");
}
/******************************************************************************
OR use class
/******************************************************************************/
try{
   
$result = db()->q('select * from `wordlist`');
   
print_r($result);
    echo(
"\nFields: " . db()->f());
    echo(
"\nRows: " . db()->r());
    echo(
"\nCounter: " . db()->i());
    echo(
"\nTimer: " . db()->t());
}
catch(
db_Exeption $e){
    echo(
$e->getMessage() . ' on line ' . $e->getLine() . "\n");
}
/******************************************************************************/