---------- Forwarded message ---------- From: Alain Roger <raf.news@xxxxxxxxx> Date: Nov 11, 2006 12:26 PM Subject: Re: MDB2 simple test To: Mark Wiesemann <wiesemann@xxxxxxx> I have a main_includes.php which include_once/require_once all needed things like MDB2.php or setpath for /pear folder Anyway, you are right. issue is on the Query command. Here is the error message : MDB2 Error: unknown error _doQuery: [Error message: Could not execute statement] [Last executed query: SELECT * FROM articles] but it does not help me so much this error. Ok, it can not execute the query but why ? example if from the PEAR help file :-( Al. On 11/11/06, Mark Wiesemann <wiesemann@xxxxxxx> wrote:
[FYI: This is a copy of a message posted to <news:php.pear.general> Message-ID: <5ci47h8nwi4o.w6h7tbcd21g8$.dlg@xxxxxxxxxx>] Alain Roger wrote: > As i'm new to PEAR world, i try to understand how does it work. > for that i took the MDB2 and try to use it with PostgreSQL. > > here is a basic sample extract from PEAR help file and only modified. > > require_once 'Pear/MDB2.php'; This line should be better: require_once 'MDB2.php'; (and the PEAR directory should be in your include_path) > $dsn = 'pgsql://login:pwd@dbname'; > > $mdb2 =& MDB2::connect($dsn); > if (PEAR::isError($mdb2)) > { > die($mdb2->getMessage()); > } > > $res =& $mdb2->query('SELECT * FROM articles'); You need to an error check here: if (PEAR::isError($res)) { die($res->getMessage() . '<br />' . $res->getDebugInfo()); } It's very likely that the following error about fetchRow() is caused because the query failed: fetchRow() would then be called on an MDB2_Error (or PEAR_Error) object which, of course, does not have a fetchRow() method. > while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) > { > echo $row['title'] . ', ' . $row['content'] . "\n"; > } > $res->free(); > > when i try this code, the following error is raised : > Call to undefined method MDB2_Error::fetchRow() which points to ==> while > ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) Regards, Mark