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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)