using adodb in UDT to query another database [SOLVED]

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm

using adodb in UDT to query another database [SOLVED]

Post 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,
Last edited by rotezecke on Wed Nov 06, 2013 12:56 am, edited 2 times in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: using adodb in UDT to query another database

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm

Re: using adodb in UDT to query another database

Post 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)
Last edited by rotezecke on Tue Nov 05, 2013 11:24 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: using adodb in UDT to query another database

Post by calguy1000 »

as the script is aborted at that point.
Then you need to look at your php error logs.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: using adodb in UDT to query another database

Post 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();
}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm

Re: using adodb in UDT to query another database

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “The Lounge”