testdsn.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. ini_set('max_execution_time', 0);
  3. require_once 'auth.php';
  4. #$rs = $adodb->Execute("SELECT * FROM qb_config ".
  5. #" WHERE tableid = ? ", array($_POST['tableid']));
  6. #if ($rs->EOF) {
  7. # die('Error: Empty Data (EOF)');
  8. #}
  9. #$odbc_dsn = $rs->fields['dsn'];
  10. #$sql = $rs->fields['sqlimport'];
  11. $odbc_dsn = $_POST['dsn'];
  12. $sql = $_POST['sqlimport'];
  13. if (empty($odbc_dsn)) {
  14. die("Error: Empty DSN");
  15. }
  16. echo "DSN: ".$odbc_dsn."<br>";
  17. $odbc =& ADONewConnection($odbc_dsn);
  18. if (!$odbc) {
  19. die($odbc->ErrorMsg());
  20. }
  21. $odbc->SetFetchMode(ADODB_FETCH_ASSOC);
  22. echo "Connect: OK<br/>";
  23. echo "<hr>";
  24. $arrTables = $odbc->MetaTables();
  25. if (!is_array($arrTables) || count($arrTables) == 0) {
  26. die("Error: Empty MetaTables<br/>".$odbc->ErrorMsg());
  27. }
  28. echo "MetaTables: ".count($arrTables)." tables =&gt; ".implode(", ", $arrTables)."<br>";
  29. echo "<hr>";
  30. if (!$sql) {
  31. die("Error: Empty SQL Import");
  32. }
  33. echo "SQL: ".$sql."<br>";
  34. echo "<hr>";
  35. $rs = $odbc->Execute($sql);
  36. if (!is_object($rs)) echo $odbc->ErrorMsg();
  37. else {
  38. $arr = array();
  39. for ($i = 0, $n = $rs->FieldCount(); $i < $n; $i++) {
  40. $fieldobj = $rs->FetchField($i);
  41. $arr[] = $fieldobj->name;
  42. }
  43. $i = $rs->RecordCount();
  44. echo "Found ".$n." fields => ".implode(", ", $arr)."<br/>";
  45. echo "Found ".$i." records.<br>";
  46. if (!$rs->EOF) echo "First record: '".implode("', '", $rs->fields)."'<br/>";
  47. echo "<script language=javascript>
  48. if (opener.document.forms[0].sqlcreate.value == '') {
  49. opener.document.forms[0].sqlcreate.value = ' ".implode(" varchar(255), \\n ", $arr).
  50. " varchar(255)\\n';
  51. }
  52. </script>";
  53. }
  54. ?>