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); // Einfacher SELECT mit Ausgabe $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 für UPDATE und affectedRows() $dbc->query("UPDATE news SET titel = 'Txt-Db-Api goes PEAR' WHERE id = '5' "); print "Affected Rows: " . $dbc->affectedRows(); // Andere Tests: // getAll() liefert alle Datensätze // getCol() liefert nur eine bestimmte Spalte (0=erste Spaltem, 1=zweite, ...) 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 |