PDA

View Full Version : php mysql using PEAR adodb connecting but returning null ressult


Stooshie
02-03-2010, 12:46 PM
Hi there,

We have recently changed servers and I am having a problem getting php to return results from MySql using the PEAR adodb extension.

PhpMyAdmin connects and returns results fine and I can even go to a SQL box, type in some SQL and get a result back.

However, when I write my own php it connects but the return value from the query is null and I get an error when I try to return FetchRow() from it.

Interestingly the Exception is NOT called.

include("adodb/adodb.inc.php");

$DB_Test = &NewADOConnection('mysql');

$DB_Test->PConnect("localhost","username", "password", "db");

$sql = "
SELECT
MAX(id) as max_id
FROM
table
";

try
{
$result = $DB_Test->Execute($sql);
$row = $result->FetchRow();
$table_id = $row["max_id"];
}
catch(Exception $e)
{
echo($e->getMessage());
}
echo($table_id);

When I do print_r on $DB_Test it seems to be populated OK

[databaseType] => mysql
[dataProvider] => mysql
[hasInsertID] => 1
[hasAffectedRows] => 1
[metaTablesSQL] => SHOW TABLES
[metaColumnsSQL] => SHOW COLUMNS FROM `%s`
[fmtTimeStamp] => 'Y-m-d H:i:s'
[hasLimit] => 1
[hasMoveFirst] => 1
[hasGenID] => 1
[isoDates] => 1
[sysDate] => CURDATE()
[sysTimeStamp] => NOW()
[hasTransactions] =>
[forceNewConnect] =>
[poorAffectedRows] => 1
[clientFlags] => 0
[substr] => substring
[nameQuote] => `
[compat323] =>
[_genIDSQL] => update %s set id=LAST_INSERT_ID(id+1);
[_genSeqSQL] => create table %s (id int not null)
[_genSeqCountSQL] => select count(*) from %s
[_genSeq2SQL] => insert into %s values (%s)
[_dropSeqSQL] => drop table %s
[database] => ivimeds
[host] => localhost
[user] => masteruser
[password] => masteruser
[debug] =>
[maxblobsize] => 262144
[concat_operator] => +
[length] => length
[random] => rand()
[upperCase] => upper
[fmtDate] => 'Y-m-d'
[true] => 1
[false] => 0
[replaceQuote] => \'
[charSet] =>
[metaDatabasesSQL] =>
[uniqueOrderBy] =>
[emptyDate] =>  
[emptyTimeStamp] =>  
[lastInsID] =>
[hasTop] =>
[readOnly] =>
[genID] => 0
[raiseErrorFn] =>
[cacheSecs] => 3600
[memCache] =>
[memCacheHost] =>
[memCachePort] => 11211
[memCacheCompress] =>
[arrayClass] => ADORecordSet_array
[noNullStrings] =>
[numCacheHits] => 0
[numCacheMisses] => 0
[pageExecuteCountRows] => 1
[uniqueSort] =>
[leftOuter] =>
[rightOuter] =>
[ansiOuter] =>
[autoRollback] =>
[fnExecute] =>
[fnCacheExecute] =>
[blobEncodeType] =>
[rsPrefix] => ADORecordSet_
[autoCommit] => 1
[transOff] => 0
[transCnt] => 0
[fetchMode] =>
[null2null] => null
[_oldRaiseFn] =>
[_transOK] =>
[_connectionID] => Resource id #7
[_errorMsg] =>
[_errorCode] =>
[_queryID] =>
[_isPersistentConnection] => 1
[_bindInputArray] =>
[_evalAll] =>
[_affected] =>
[_logsql] =>
[_transmode] =>
[databaseName] => ivimeds


Is there anything missing from the $DB_Object? has anyone come across this before?

The versions I am using are:

PHP Version: 5.2.10
MySQL Server version: 5.0.89-community

Andrew.

Old Pedant
02-03-2010, 07:55 PM
Well, not to ask a silly question...

I have no idea what PEAR is, but if it uses Microsoft's ADODB, then I assume this is intended for a Windows server, yes?

And if that is so, then have you installed MyODBC to connect MySQL to ADODB?

Stooshie
02-04-2010, 10:03 AM
Hi there,

PEAR is a collection of PHP extensions.

The adodb is an extension which allows you to connect to many different types of database. It is written in PHP and can be run on any server using PHP. Our server is *nix.

It works on our old server so I am trying to find out what settings could be different and nothing except some very minor PHP and MySQL upgrades (e.g. PHP 5.2.10 rather than 5.2.6).

Old Pedant
02-04-2010, 06:19 PM
Fascinating. They use the same acronym the MS uses. "ADODB". Wonder what it stands for in PEAR? ("ActiveX Data Objects" or something like that with MS.)