PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Giorgos   ActiveDBLib   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: A little example script
Class: ActiveDBLib
Database abstraction library independent wrapper
Author: By
Last change:
Date: 19 years ago
Size: 2,770 bytes
 

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>