I use ADODB and have set it up to run with multiple databases concurrently, so my code looks a little funky.
but here are the parts of interest.
I connect to each of my databases using ADODB and put the resource ids in an array. This is an example of one of those connections. I also start the SQL statement for that database.
// load adodb library
require_once 'adodb/Adodb.inc.php';
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$ADODB_COUNTRECS = false;
$db_name = "DEV";
// Connect to Oracle
$db[$db_name] = NewADOConnection('oci8');
$Connect_Result = $db[$db_name]->Connect("server:port", "user", "password", "connect string");
if ($Connect_Result === false) {
unset($db[$db_name]);
$log[] = "Warning : Unable to connect to Oracle database ($db_name)<br>";
}
$db[$db_name]->debug=true;
$sql_select[$db_name] = "SELECT MESSAGEID, SENDER, RECEIVER, APPLICATION, CREATETIME, CONTROLNO FROM MMC_MESSAGE";
I then retreive the data submitted from a form and load a $filers array (not shown). I then append the results from the $filters array to the query and execute the query for each database. The select resource id is then placed on another array.
//Execute query
while (list($key,$cur_db) = each($db)) {
if (is_object($cur_db)) {
$query = $sql_select[$key];
if (isset($filters[$key])) {
$query .= " WHERE $filter";
}
$query .= " ORDER BY CREATETIME ".SORT_DIRECTION.", MESSAGEID";
//$query = "SELECT MESSAGEID,SENDER,RECEIVER,APPLICATION,TO_CHAR(CREATETIME,'YYYY/MM/DD HH:MI:SS AM') AS CREATETIME,CONTROLNO FROM MMC_MESSAGE WHERE CREATETIME > '01-Oct-05' ORDER BY CREATETIME DESC, MESSAGEID";
//$query = "SELECT COUNT(*) FROM MMC_MESSAGE WHERE CREATETIME BETWEEN '01-Oct-05' AND '01-Oct-06' ORDER BY CREATETIME DESC, MESSAGEID";
$log[] = log_message("I1", "Execute Query [$key]");
$log[] = log_message("I1", "SQL : $query");
$Select_Result[$key] =& $cur_db->Execute($query);
if ($Select_Result[$key] === false) {
unset($Select_Result[$key]);
$log[] = log_message("W1","Warning : Unable to execute query ($key)");
continue;
}
}
}
if (count($Select_Result) <= 0) {
$log[] = log_message("E1","Error : No queries were successful");
quit(&$smarty,$log);
}
Here I loop through the resource id array for the successful queries and pull the results. I also flush the output after FLUSH_LIMIT records (currently set to 100).
//Get results
$curr_count = 0;
$records = array();
$result_count = array();
while (count($Select_Result) > 0) {
while (list($key,$cur_select) = each($Select_Result)) {
$j=0;
while (!$cur_select->EOF && $j <= FLUSH_LIMIT) {
$j++;
$records[] = $cur_select->fields;
$cur_select->MoveNext();
}
$result_count[$key] += $j;
$curr_count += $j;
if($cur_select->EOF) {
unset($Select_Result[$key]);
}
}
//Flush output to browser
if (count($records)>0) {
$records = array_csort($records,"CREATETIME",CSORT_DIRECTION,"MESSAGEID");
$curr_records = array_slice($records,0,FLUSH_LIMIT);
$records = array_slice($records,FLUSH_LIMIT);
$smarty->assign('records',$curr_records);
$smarty->display('index_body.tpl');
ob_flush();
flush();
reset($Select_Result);
}
}
This works fine as long as I do not have a data in my where clause.
Please let me know if you need more iformation.
Thanks
Steve