function handle_pear_error($res) { if (PEAR::isError($res)) { $cause = "<p><b>Standard Message:</b> " . $res->getMessage() . "</p>\n" . "<p><b>User Information:</b> " . $res->getUserInfo() . "</p>\n" . "<p><b>Debug Information:</b> " . $res->getDebugInfo() . "</p>"; throw new GdaException($cause, false); } } echo "\n"; if (!isset($cnc, $dsn)) { echo "<p><b>ERROR:</b> No connection defined!</p>\n"; exit(1); } if ($test_connections) { foreach ($cnc as $dbname => $dbpass) { echo "<h2>Connection '" . $dbname . "'</h2>"; try { $mdb2 = MDB2::connect($dsn[$dbname]); handle_pear_error($mdb2); echo "OK.\n"; } catch (GdaException $e) { echo "FAILED!\n" . $e->getMessage() . "\n"; } } } else { echo "<p>Connections listed below but not tested (set <tt>\$test_connections</tt> to <tt>true</tt> in the <tt>gda-tester.php</tt> file to change):</p>\n"; echo "<ul>\n"; foreach ($cnc as $dbname => $dbpass) { echo "<li>Connection '" . $dbname . "'</li>\n"; } echo "</ul>\n"; }
function get_catalog($reply, &$mdb2) { global $catalog; if (!$catalog) { $res = MDB2::parseDSN($_SESSION['dsn']); handle_pear_error($res, $reply); $catalog = $res['database']; } return $catalog; }
function handle_pear_error($res) { if (PEAR::isError($res)) { $cause = "\tStandard Message [" . $res->getMessage() . "]\n" . "\tUser Information [" . $res->getUserInfo() . "]\n" . "\tDebug Information [" . $res->getDebugInfo() . "]"; echo "ERROR: {$cause}\n"; } } $mdb2 = MDB2::connect("mysql://*****:*****@unix(/tmp/mysql.sock)/sales"); handle_pear_error($mdb2); $mdb2->loadModule('Reverse', null, true); $prep = $mdb2->prepare((string) "SHOW VARIABLES WHERE Variable_name = 'lower_case_table_names'", null, MDB2_PREPARE_RESULT); //$prep = $mdb2->prepare((string) "Select * from information_schema.tables", // null, MDB2_PREPARE_RESULT); handle_pear_error($prep); $res = $prep->execute(null); handle_pear_error($res); $reply = new SimpleXMLElement("<reply></reply>"); $node = $reply->addChild("gda_array", null); $ncols = $res->numCols(); /* compute field type */ echo "M1\n"; $tableinfo = $mdb2->reverse->tableInfo($res, NULL); echo "M2\n"; if (!PEAR::isError($tableinfo)) { //var_dump($tableinfo); $gtypes = array(); $dbtypes = array(); for ($i = 0; $i < $ncols; $i++) { $gtypes[$i] = mdb2_type_to_gtype($tableinfo[$i]['mdb2type']); $dbtypes[$i] = $tableinfo[$i]['type']; }
function do_exec($reply, &$mdb2, $pstmt_hash, $sql, $type_is_result, $argsnode) { /* get prepared statement */ global $prepared_statements; if (isset($pstmt_hash)) { $prep = $prepared_statements[(string) $pstmt_hash]; } if (!isset($prep)) { $prep = do_prepare($reply, $mdb2, (string) $sql, $type_is_result, $argsnode); } /* handle arguments */ if ($argsnode) { $args = array(); foreach ($argsnode->children() as $node) { if ($node->getName() == "arg") { $args[] = $node[0]; } } } else { $args = null; } /* actual execution */ $res = $prep->execute($args); handle_pear_error($res, $reply); if ($type_is_result) { $node = $reply->addChild("gda_array", null); $ncols = $res->numCols(); /* compute field type */ $tableinfo = $mdb2->reverse->tableInfo($res, NULL); if (!PEAR::isError($tableinfo)) { //var_dump($tableinfo); $gtypes = array(); $dbtypes = array(); for ($i = 0; $i < $ncols; $i++) { $gtypes[$i] = mdb2_type_to_gtype($tableinfo[$i]['mdb2type']); $dbtypes[$i] = $tableinfo[$i]['type']; } } $colnames = $res->getColumnNames(); if (PEAR::isError($colnames)) { unset($colnames); } for ($i = 0; $i < $ncols; $i++) { $field = $node->addChild("gda_array_field", null); $field->addAttribute("id", "FI" . $i); if (isset($colnames)) { foreach ($colnames as $name => $pos) { if ($pos == $i) { $field->addAttribute("name", $name); break; } } } if (isset($gtypes)) { $field->addAttribute("gdatype", $gtypes[$i]); } else { $field->addAttribute("gdatype", "string"); } if (isset($dbtypes) && $dbtypes[$i]) { $field->addAttribute("dbtype", $dbtypes[$i]); } $field->addAttribute("nullok", "TRUE"); } $data = $node->addChild("gda_array_data", null); while ($row = $res->fetchRow()) { // MDB2's default fetchmode is MDB2_FETCHMODE_ORDERED $xmlrow = $data->addChild("gda_array_row", null); for ($i = 0; $i < $ncols; $i++) { $val = $xmlrow->addChild("gda_value"); $val[0] = str_replace("&", "&", $row[$i]); } } } else { $reply->addChild("impacted_rows", (string) $res); } }