Login   Register  
PHP Classes
elePHPant
Icontem

File: mysql2object/example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Arkadiusz Malinski  >  mysql2object  >  mysql2object/example.php  >  Download  
File: mysql2object/example.php
Role: Example script
Content type: text/plain
Description: Example of using
Class: mysql2object
Manipulate MySQL databases without using SQL
Author: By
Last change: 1
Date: 8 years ago
Size: 3,559 bytes
 

Contents

Class file image Download
<?
    
require_once('database.class.php');
    
    echo 
'<pre>';
    try {

        
$testDatabase = new Database(new DB('mysql://admin:123456@localhost/testDatabase'));
        
        echo 
'<b>Example 1 - get all tables in database:</b><br>';
        
print_r($testDatabase->all); echo '<br>';
        
        echo 
'<b>Example 2 - get all columns from selected table:</b><br>';
        
print_r($testDatabase->pp_users->all); echo '<br>';
        
        echo 
'<b>Example 3 - get informations on selected table :</b><br>';
        echo 
'<li>Table name: '.$testDatabase->pp_users->Name.'<br>';
        echo 
'<li>Engine: '.$testDatabase->pp_users->Engine.'<br>';
        echo 
'<li>Version: '.$testDatabase->pp_users->Version.'<br>';
        echo 
'<li>Row format: '.$testDatabase->pp_users->Row_format.'<br>';
        echo 
'<li>Number of rows: '.$testDatabase->pp_users->Rows.'<br>';
        echo 
'<li>Number of columns: '.$testDatabase->pp_users->Columns.'<br>';
        echo 
'<li>...etc...<br><br>';
        
        echo 
'<b>Example 4 - get all values from selected column:</b><br>';
        
print_r($testDatabase->pp_users->username->all); echo '<br>';
        
        echo 
'<b>Example 5 - get informations on selected column :</b><br>';
        echo 
'<li>Column type: '.$testDatabase->pp_users->username->Type.'<br>';
        echo 
'<li>Null: '.$testDatabase->pp_users->username->Null.'<br>';
        echo 
'<li>Key: '.$testDatabase->pp_users->username->Key.'<br>';
        echo 
'<li>Default: '.$testDatabase->pp_users->username->Default.'<br>';
        echo 
'<li>Extra: '.$testDatabase->pp_users->username->Extra.'<br>';
        echo 
'<br>';

        echo 
'<b>Example 6 - get selected value from selected column:</b><br>';
        
print_r($testDatabase->pp_users->username(5)); echo '<br><br>';
        
        echo 
'<b>Example 7 - gets all data sorted by selected columns:</b><br>';
        
print_r($testDatabase->pp_users->sort('username desc','email')); echo '<br>';

        echo 
'<b>Example 8 - gets data from some selected columns:</b><br>';
        
print_r($testDatabase->pp_users->columns('username','email')); echo '<br>';
        
        echo 
'<b>Example 9 - gets data from all columns which accept one/more conditions :</b><br>';
        
print_r($testDatabase->pp_users->select(array('views''>'900),array('userid''<'10))); echo '<br>';

        echo 
'<b>Example 10 - gets data from one column which accept one/more conditions :</b><br>';
        
print_r($testDatabase->pp_users->userid->select(array('>'5),array('<',10))); echo '<br>';

        echo 
'<b>Example 11 - join data from selected table on defined condition :</b><br>';
        
print_r($testDatabase->pp_users->join($testDatabase->pp_usergroups$testDatabase->pp_users->usergroupid$testDatabase->pp_usergroups->groupid));

        echo 
'<b>Example 12 - union data from two tables :</b><br>';
        
print_r($testDatabase->forum_usertitle->union($testDatabase->areckitest));

        echo 
'<b>Example 13 - gets data with composed functions/conditions :</b><br>';
        
$testDatabase->pp_users->createComposedCondition('test1');
        
$testDatabase->pp_users->join($testDatabase->pp_usergroups$testDatabase->pp_users->usergroupid$testDatabase->pp_usergroups->groupid);
        
$testDatabase->pp_users->select(array('views''>'0));
        
$testDatabase->pp_users->columns('username','email','groupname');
        
$testDatabase->pp_users->union($testDatabase->old_pp_users, array('username'=>'old_username','email'=>'old_email''groupname'=>'password'));
        
$testDatabase->pp_users->sort('email desc');
        
$testDatabase->pp_users->endComposedcondition('test1');
        
print_r($testDatabase->pp_users->test1);

        
    } catch (
Exception $xx) {
        echo 
'Error: '.$xx->getMessage();
    }
    
    echo 
'</pre>';
?>