从远程Web服务器连接到本地数据库 [英] Connecting to local Database from remote web server

查看:231
本文介绍了从远程Web服务器连接到本地数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从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'] . "\n";
 $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");
   }
}

谢谢您的时间!

推荐答案

首先:发生此错误是因为您没有安装ODBC PHP扩展.

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

检查 http://php.net/manual/en/odbc.installation.php .

在debian发行版中,您可以使用apt-get install php5-odbc解决此问题,但是您也可以通过托管服务提供商进行检查.

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

当您看到Call to undefined function时,必须始终检查php.net以确保函数名称或扩展名未加载.

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:我认为您正在尝试在两个数据库之间比较/传输数据,对吗?

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

PS 2:确保您的服务器可以访问ODBC地址. Web服务器不是您的开发机器,因此localhost不是真正的localhost;)

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 ;)

这篇关于从远程Web服务器连接到本地数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆