PHP Classes
Icontem

File: example.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 Giorgos  >  ActiveDBLib  >  example.php  
File: example.php
Role: Example script
Content type: text/plain
Description: A little example script
Class: ActiveDBLib
Database abstraction library independent wrapper
 

Contents

Class file image Download
<?php
require_once("activeDBLib.php");
/*
==============================================================================================
Set your database connection variables below
==============================================================================================
*/
$dbtype="mysql"// the class uses mysql if no database abstraction library is included
$dbhost="localhost"// database server host
$dbuser="root"// database user
$dbpass=""// database password
$dbname="test"// database name
$SQL="SHOW TABLES"// SQL statement
/*
==============================================================================================
Uncomment the following to test the result, when a database abstraction library is included
==============================================================================================
*/
//include("adodb/adodb.inc.php");
//include("peardb/DB.php");
//include("metabase/metabase_interface.php");
//include("metabase/metabase_database.php");
//include("metabase/metabase_mysql.php");
/*
==============================================================================================
Connect to database and send the query
==============================================================================================
*/
$db=new activeDBLib($dbtype);
$db->debug(); // catch all errors and exit the application if any
$db->connect($dbhost,$dbuser,$dbpass,$dbname);
$db->execute($SQL);
?>
<?php 
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><title>activeDBLib Example</title>
</head>
<body>
Database Type: <b><?php print $db->getDriver(); ?></b><br />
Database Library: <b><?php print $db->getDBLibrary(); ?></b><br />
SQL STATEMENT: <b><?php print $SQL?></b><br />
ERROR: <b><?php print $db->error(); ?></b><br />
RESULT ROWS: <b><?php print $db->rowCount(); ?></b><br />
RESULT FIELDS: <b><?php print $db->fieldCount(); ?></b><br />
FIELD INFORMATION TABLE<br />
<table>
<tr><td>Name(s):</td><?php for ($i=0;$i<$db->fieldCount();$i++) print "<td><b>".$db->getField($i,"name")."</b></td>"?></tr>
<tr><td>Type(s):</td><?php for ($i=0;$i<$db->fieldCount();$i++) print "<td><b>".$db->getField($i,"type")."</b></td>"?></tr>
<tr><td>Length(s):</td><?php for ($i=0;$i<$db->fieldCount();$i++) print "<td><b>".$db->getField($i,"max_length")."</b></td>"?></tr>
</table>
RESULT TABLE<br />
<table>
<?php
$countInit
=1;
while (
$row=$db->GetArray()){
    print 
"<tr><td>Row ".$countInit++.": </td>";
    for (
$x=0;$x<$db->fieldCount();$x++) print "<td><b>".$row[$x]."</b></td>";
    print 
"</tr>\n";
}
?>
</table>
</body>
</html>

 
  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