Page 1 of 1

using adodb in UDT to query another database [SOLVED]

Posted: Tue Nov 05, 2013 11:00 pm
by rotezecke
I'm in the process of updating old UDTs that use mysql_xxx functions. I found many examples that showed how to query the CMSMS database. however, I need to query another database.
so far i got:

Code: Select all

require "ms_config/db.php";
//connect - using ADOdb lite syntax
$db = NewADOConnection('mysql');
$db->Connect($db_host,$db_user,$db_pw,$db_db);
$query1 = "SELECT * FROM sometable";
$result1 = $db->Execute($query1);
which is fine, but i cannot use the FetchRow() method

Code: Select all

 while ($result1 && $row = $result1->FetchRow())
it appears that i can only use adodb lite functions, but

Code: Select all

$db = cmsms()->GetDb
gives me access to more functions. i managed to retrieve single records using GetRows() or GetAll(). however, I assume even that is done incorrectly, as my field is returned in $row[0]['field'] and not $row['field']. is this to be expected?
but more importantly, what is the correct way to loop through while condition? or how do i extend the library and include what i believe is called "pear" in cmsms UDT? if you know of a beginner's manual / tutorial site, a link would be much appreciated.
Thanks,

Re: using adodb in UDT to query another database

Posted: Tue Nov 05, 2013 11:11 pm
by calguy1000
which is fine, but i cannot use the FetchRow() method
means what exactly?

if the $result1 object is not an object, then the query probably failed.

Check $db->ErrorMsg();

btw: You shouldn't have to include/require any files to use the adodb stuff as CMSMS has already done that.

Re: using adodb in UDT to query another database

Posted: Tue Nov 05, 2013 11:22 pm
by rotezecke
I get:
Fatal error: Call to undefined method mysql_driver_ResultSet::FetchRows() in /var/www/cmsms/lib/classes/class.usertagoperations.inc.php(265) : eval()'d code on line 17
$db->ErrorMsg();

doesnt help, as the script is aborted at that point.

the require calls the credentials to the other database.

BTW: using CMSMS 1.11.9 on PHP5.4.4-14 deb7u5 (debian)

Re: using adodb in UDT to query another database

Posted: Tue Nov 05, 2013 11:23 pm
by calguy1000
as the script is aborted at that point.
Then you need to look at your php error logs.

Re: using adodb in UDT to query another database

Posted: Tue Nov 05, 2013 11:38 pm
by calguy1000

Code: Select all

$str = 'pear:date:extend';
$db = NewADOConnection('mysqli',$str);
The 'FetchRow' method is part of the 'pear' extension.

BTW... this method is slightly faster, and will work without the 'str' stuff above:

Code: Select all

$dbr = $db->Execute($query);
while( $dbr && !$dbr->EOF ) {
  print_r($dbr->fields);
  $dbr->MoveNext();
}

Re: using adodb in UDT to query another database

Posted: Wed Nov 06, 2013 12:55 am
by rotezecke
Thanks a lot.

Btw

Code: Select all

$dbr->fields
actually works whereas

Code: Select all

$dbr->Fields
does not. the latter is featured here http://adodblite.sourceforge.net/functions.php

Re: using adodb in UDT to query another database [SOLVED]

Posted: Wed Nov 06, 2013 1:09 am
by calguy1000
that's prolly cuz 'fields' (lower case f) is a member variable
whereas 'Fields' (upper case F) is a method (function).

Though I have never dug that deeply into accuracy of the adodb/adodb-lite documentation.