PHP Classes
Icontem

File: ___cases_of_use.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Michal Palma  >  SQL databases interface  >  ___cases_of_use.php  
File: ___cases_of_use.php
Role: Example script
Content type: text/plain
Description: Cases of use
Class: SQL databases interface
Database abstraction library independent wrapper
 

Contents

Class file image Download
<?php
/*
* Some cases of use (for your use you must reconfigure Connection Attributes in DbSelector class - read readmeFirst.txt)
* @package DbControl
* @date 2006-01-11
*/

require("_preload.php");

$task "test";
$query_select "select * from your_db_table_name";
$database_name "your_db_schema_name";

try {
    
$dbC = new DbControl($task"cp1250");
    
$dbC->selectDb($database_name);
    
$dbC->setQuery($query_select);
    
$dbR $dbC->initiate();
    echo 
"We found "$dbR->getNumRows() ." rows in database result.";
    echo 
"<table border='1'>";
    echo 
"<tr>";
    foreach (
$dbR->getColnames() as $colname) {
        echo  
"<th>"$colname ."</th>";
    }
    echo 
"</tr>";
    while (
$dbR->next()) {
        echo 
"<tr>";
        foreach(
$dbR->get("*") as $colname => $col) {
        
# you can use direct columnname ($dbR->colName)
            
echo "<td>$col</td>";
        }
        echo 
"</tr>";
    }
    echo 
"</table>";
}
catch (Exception $e) {
    echo 
"<hr />";
    echo 
"Exception code:  <font style='color:blue'>"$e->getCode() ."</font>";
    echo 
"<br />";
    echo 
"Exception message: <font style='color:blue'>"nl2br($e->getMessage()) ."</font>";
    echo 
"<br />";
    echo 
"Thrown by: '"$e->getFile() ."'";
    echo 
"<br />";
    echo 
"on line: '"$e->getLine() ."'.";
    echo 
"<br />";
    echo 
"<br />";
    echo 
"Stack trace:";
    echo 
"<br />";
    echo 
nl2br($e->getTraceAsString());
    echo 
"<hr />";
}

/*
try {
    $query = "INSERT INTO user VALUES('', 'palmic', 'heslo', 'user', 0)";
    $dbC = new DbControl($task);
    $dbC->selectDb("wwera");
    $dbC->transactionStart();
    $dbC->setQuery($query);
    $dbC->initiate();
    echo "Id of last inserted record is '". $dbC->getLastId() ."'";
    $dbC->transactionCommit();
}
catch (Exception $e) {
    echo "<hr />";
    echo "Exception code:  <font style='color:blue'>". $e->getCode() ."</font>";
    echo "<br />";
    echo "Exception message: <font style='color:blue'>". nl2br($e->getMessage()) ."</font>";
    echo "<br />";
    echo "Thrown by: '". $e->getFile() ."'";
    echo "<br />";
    echo "on line: '". $e->getLine() ."'.";
    echo "<br />";
    echo "<br />";
    echo "Stack trace:";
    echo "<br />";
    echo nl2br($e->getTraceAsString());
    echo "<hr />";
}
*/
/*
try {
    $dbC = new DbControl($task);
    $dbC->selectDb("wwera");
    $dbC->setQuery("delete from user where id > 1");
    $dbC->transactionStart($autoCommit = true);
    $dbC->initiate();
    $dbC->setQuery("select * from user");
    $dbR = $dbC->initiate();

    echo "<table border='1'>";
    while ($dbR->next()) {
        echo "<tr>";
        foreach($dbR->get("*") as $colname => $col) {
            echo "<td>$colname = $col</td>";
        }
        echo "</tr>";
    }
    echo "</table>";

}
catch (Exception $e) {
    echo "<hr />";
    echo "Exception code:  <font style='color:blue'>". $e->getCode() ."</font>";
    echo "<br />";
    echo "Exception message: <font style='color:blue'>". nl2br($e->getMessage()) ."</font>";
    echo "<br />";
    echo "Thrown by: '". $e->getFile() ."'";
    echo "<br />";
    echo "on line: '". $e->getLine() ."'.";
    echo "<br />";
    echo "<br />";
    echo "Stack trace:";
    echo "<br />";
    echo nl2br($e->getTraceAsString());
    echo "<hr />";
}
*/
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products