Using Txt-db-api with PEAR

In the pear Directory there is a file txtdbapi.php.
This File is a Text-Db-Api Database-Wrapper for PEAR.

Installation

Copy this file to the other Database Wrapper into the directory

/usr/share/php/DB/ (common for *nix installations) or <php-installation>/PEAR/DB (windows).

The connect-String for the Txt-Db-Api looks like this:
txtdbapi://localhost/<dbname>


Example


A Database Query could look like this:
Code:
<?

include "DB.php";
include "txt-db-api.php";

$dbc = DB::connect("txtdbapi://localhost/soulspring");
//$dbc = DB::connect("mysql://user:password@localhost/soulspring");

$dbc->setFetchMode(DB_FETCHMODE_ASSOC);

// Simple SELECT with output
$result = $dbc->query("SELECT * FROM news");

if (PEAR::isError($result)) {
   print $result->getUserInfo();
}

if ($result->numRows()) {
   $row = array();
   while($row = $result->fetchRow()) {
      print_r($row);
   }
} else {
   print "No results available\n";
}

// Test for UPDATE and affectedRows()
$dbc->query("UPDATE news SET titel = 'Txt-Db-Api goes PEAR' WHERE id = '5' ");
print "Affected Rows: " . $dbc->affectedRows();

// Other Tests:
// getAll() returns all Records
// getCol() returns a single Column
print_r($dbc->getAll("SELECT * FROM programm", null, DB_FETCHMODE_ASSOC));
print_r($dbc->getCol("SELECT * FROM programm", 1));

$dbc->disconnect();

?>


If you have no access to the PEAR directory, it should suffice (I'm not sure) to copy only the following files to the webserver:

Code:
WEB-ROOT
|
|--include
|  |
|  `-- DB
|      |
|      |-- common.php
|      |-- storage.php
|      `-- txtdbapi.php
|-- DB.php
`-- PEAR.php


In the source you can include the PEAR::DB Module like this:
include "/include/DB.php"

This
Workaround is experimental and may be unstable.