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(); ?> |
Code: |
WEB-ROOT | |--include | | | `-- DB | | | |-- common.php | |-- storage.php | `-- txtdbapi.php |-- DB.php `-- PEAR.php |