Monday, October 27, 2008

Using ClientFlags in ADODB Lite to Execute MySQL Stored Procedures

I am currently programming a cron in PHP using ADODB connection. (See sample connection.)

$dbConn =& ADONewConnection(DB_DRIVER);
$dbConn->Connect($dbServer, $dbUsername, $dbPassword, $dbName);
$dbConn->SetFetchMode(ADODB_FETCH_ASSOC);

I thought it worked fine but when I checked on the supposed updates in the database, I found that the stored proc wasn't executed. Upon checking on the net (and I might say it took a while on pinpointing the real problem due to limited sources), I found a solution that inserted the ff. code for clientflags similar with mysql connections:

$dbConn->clientFlags = 131074;

I needed to understand what 131074 means until I found an explanation (ironically on Drupal) with regards to this, telling that the value sets the client flags to CLIENT_MULTI_RESULTS.

The stored procedure doesn't know ahead of time how many results will be returned so the client needs to support reading any multiple of results.

So here's the corrected code:
$dbConn =& ADONewConnection(DB_DRIVER);
$dbConn->clientFlags = 131074;
$dbConn->Connect($dbServer, $dbUsername, $dbPassword, $dbName);
$dbConn->SetFetchMode(ADODB_FETCH_ASSOC);

No comments:

Your Ad Here