我正在尝试从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.
检查 php/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以确保函数名称或扩展名未加载.
When you see a Call to undefined function you always must check the php 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服务器连接到本地数据库
发布评论