doujuegai8830 2014-10-08 16:13
浏览 128
已采纳

从远程Web服务器连接到本地数据库

I am trying to connect to my local Database from the webserver but i get

Fatal error: Call to undefined function odbc_connect() 
             in -/-/-/7001238/web/s/sage2.php on line 15"

Any help on how to fix issue.

Here is the code i used to connect.

 $odbc['dsn'] = "Sage50";
 $odbc['user'] = "Peach";
 $odbc['pass'] = "XXXX";
 $mysql['host'] = "localhost";
 $mysql['user'] = "root";
 $mysql['pass'] = "";
 $mysql['dbname'] = "sagetest";
 $mysql['idfield'] = "id";
 $debug=true;
 // Step 1: Connect to the source ODBC and target mysql database
 if ($debug) echo "Connect to " . $odbc['dsn'] . ' as ' . $odbc['user'] . "
";
 $conn = odbc_connect($odbc['dsn'], $odbc['user'], $odbc['pass']);
 if (!$conn) {
    die("Error connecting to the ODBC database: " . odbc_errormsg());
 }
 $myconn = mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']);
 if (!$myconn)
    die("Error connecting to the MySQL database: " . $mysql_error());
 if (!mysql_select_db($mysql['dbname'], $myconn))  die("Error selecting the database: " . mysql_error());
// Step 1.5: loop through each table with steps 2-7
$allTables = odbc_tables($conn);
$tablesArray = array();
while (odbc_fetch_row($allTables)) {
   if (odbc_result($allTables, "TABLE_TYPE") == "TABLE") {
      $tablesArray[] = odbc_result($allTables, "TABLE_NAME");
   }
}

Thank you for your time!

  • 写回答

1条回答 默认 最新

  • dongyuedaochen8415 2014-10-08 16:52
    关注

    First: This error happens because you don't have the ODBC PHP extension installed.

    Check http://php.net/manual/en/odbc.installation.php too.

    In debian distros you can solve this with a apt-get install php5-odbc, but you can check this also with your hosting provider.

    When you see a Call to undefined function you always must check the php.net to be sure about the name of function, or the extension is not loaded.

    PS 1: I think you're trying to compare/transfer data between two databases, right?

    PS 2: Make sure your server can reach the ODBC address. The webserver is not your dev machine, so localhost is not the real localhost ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?