getLastError())), "
\n"; } else { // Print query results switch (pg_result_status($rs)) { case PGSQL_TUPLES_OK: // If rows returned, then display the results $num_fields = pg_numfields($rs); echo "

\n"; for ($k = 0; $k < $num_fields; $k++) { echo ""; } $i = 0; $row = pg_fetch_row($rs); while ($row !== false) { $id = (($i % 2) == 0 ? '1' : '2'); echo "\n"; foreach ($row as $k => $v) { echo ""; } echo "\n"; $row = pg_fetch_row($rs); $i++; }; echo "
", $misc->printVal(pg_fieldname($rs, $k)), "
", $misc->printVal($v, pg_fieldtype($rs, $k), array('null' => true)), "

\n"; echo $i, " {$lang['strrows']}

\n"; break; case PGSQL_COMMAND_OK: // If we have the command completion tag if (version_compare(phpversion(), '4.3', '>=')) { echo htmlspecialchars(pg_result_status($rs, PGSQL_STATUS_STRING)), "
\n"; } // Otherwise if any rows have been affected elseif ($data->conn->Affected_Rows() > 0) { echo $data->conn->Affected_Rows(), " {$lang['strrowsaff']}
\n"; } // Otherwise output nothing... break; case PGSQL_EMPTY_QUERY: break; default: break; } } } // We need to store the query in a session for editing purposes // We avoid GPC vars to avoid truncating long queries // If we came from a report, we need to look up the query if (isset($_REQUEST['subject']) && $_REQUEST['subject'] == 'report' ) { global $data, $misc; include_once('./classes/Reports.php'); $reportsdb = new Reports($status); $report = $reportsdb->getReport($_REQUEST['reportid']); $_SESSION['sqlquery'] = $report->fields['report_sql']; } elseif (isset($_POST['query'])) { // Or maybe we came from an sql form $_SESSION['sqlquery'] = $_POST['query']; } else { echo "could not find the query!!"; } // Pagination maybe set by a get link that has it as FALSE, // if that's the case, unset the variable. if (isset($_REQUEST['paginate']) && $_REQUEST['paginate'] == 'f') { unset($_REQUEST['paginate']); unset($_POST['paginate']); unset($_GET['paginate']); } // Check to see if pagination has been specified. In that case, send to display // script for pagination /* if a file is given or the request is an explain, do not paginate */ if (isset($_REQUEST['paginate']) && !(isset($_FILES['script']) && $_FILES['script']['size'] > 0) && (preg_match('/^\s*explain/i', $_SESSION['sqlquery']) == 0)) { include('./display.php'); exit; } $subject = isset($_REQUEST['subject'])? $_REQUEST['subject'] : ''; $misc->printHeader($lang['strqueryresults']); $misc->printBody(); $misc->printTrail('database'); $misc->printTitle($lang['strqueryresults']); // Set the schema search path if (isset($_REQUEST['search_path'])) { if ($data->setSearchPath(array_map('trim',explode(',',$_REQUEST['search_path']))) != 0) { $misc->printFooter(); exit; } } // May as well try to time the query if (function_exists('microtime')) { list($usec, $sec) = explode(' ', microtime()); $start_time = ((float)$usec + (float)$sec); } else $start_time = null; // Execute the query. If it's a script upload, special handling is necessary if (isset($_FILES['script']) && $_FILES['script']['size'] > 0) $data->executeScript('script', 'sqlCallback'); else { // Set fetch mode to NUM so that duplicate field names are properly returned $data->conn->setFetchMode(ADODB_FETCH_NUM); $rs = $data->conn->Execute($_SESSION['sqlquery']); // $rs will only be an object if there is no error if (is_object($rs)) { // Request was run, saving it in history if(!isset($_REQUEST['nohistory'])) $misc->saveScriptHistory($_SESSION['sqlquery']); // Now, depending on what happened do various things // First, if rows returned, then display the results if ($rs->recordCount() > 0) { echo "\n"; foreach ($rs->fields as $k => $v) { $finfo = $rs->fetchField($k); echo ""; } echo "\n"; $i = 0; while (!$rs->EOF) { $id = (($i % 2) == 0 ? '1' : '2'); echo "\n"; foreach ($rs->fields as $k => $v) { $finfo = $rs->fetchField($k); echo ""; } echo "\n"; $rs->moveNext(); $i++; } echo "
", $misc->printVal($finfo->name), "
", $misc->printVal($v, $finfo->type, array('null' => true)), "
\n"; echo "

", $rs->recordCount(), " {$lang['strrows']}

\n"; } // Otherwise if any rows have been affected elseif ($data->conn->Affected_Rows() > 0) { echo "

", $data->conn->Affected_Rows(), " {$lang['strrowsaff']}

\n"; } // Otherwise nodata to print else echo '

', $lang['strnodata'], "

\n"; } } // May as well try to time the query if ($start_time !== null) { list($usec, $sec) = explode(' ', microtime()); $end_time = ((float)$usec + (float)$sec); // Get duration in milliseconds, round to 3dp's $duration = number_format(($end_time - $start_time) * 1000, 3); } else $duration = null; // Reload the browser as we may have made schema changes $_reload_browser = true; // Display duration if we know it if ($duration !== null) { echo "

", sprintf($lang['strruntime'], $duration), "

\n"; } echo "

{$lang['strsqlexecuted']}

\n"; echo "\n"; $misc->printFooter(); ?>