php 连接 SAP Hana 数据库时调用未定义的函数 odbc_connect() 消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17859989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call to undefined function odbc_connect() message while connecting SAP Hana database
提问by ron
I used odbc_connect()
in my PHP page to connect to the HANA database. It works fine when i run it locally.
I upload the same PHP page into the server and i am getting this error:
我odbc_connect()
在我的 PHP 页面中用于连接到 HANA 数据库。当我在本地运行它时,它工作正常。我将相同的 PHP 页面上传到服务器,但出现此错误:
Fatal error: Call to undefined function odbc_connect()
The code:
编码:
$connect = odbc_connect("Team6DataSource", "TEAM6", "Password1", SQL_CUR_USE_ODBC);
Team6DataSource = datasource name.
Team6DataSource = 数据源名称。
ip address = 54.217.234.218
IP 地址 = 54.217.234.218
Can any one please help me? Thanks
谁能帮帮我吗?谢谢
回答by VIVEK-MDU
I just go through in google get this instructionthis is really helpful for you.
我刚刚在谷歌中获得了这条指令,这对你真的很有帮助。
- Download the SQL Server ODBC driver for your PHP client
platform.(Registration required.) If the SQL Server ODBC driver is not currently available for your platform, check the list of
ODBC-ODBC Bridge Client platforms. The ODBC-ODBC Bridge is an
alternative SQL Server solution from Easysoft, which you can download from this site. - Install and license the SQL Server ODBC driver on the machine where
PHP is installed. For installation instructions, see the ODBC driver
documentation. Refer to the documentation to see which environment
variables you need to set
(LD_LIBRARY_PATH, LIBPATH, LD_RUN_PATH, SHLIB_PATH depending on the driver, platform and linker).
Create an ODBC data source in
/etc/odbc.ini
that connects to theSQL Server database
you want to access from PHP. For example, this SQL Server ODBC data source connects to a SQL Server Express instance that serves the Northwind database:- Use isql to test the new data source. For example:
cd /usr/local/easysoft/unixODBC/bin
./isql -v MSSQL-PHP
- Use isql to test the new data source. For example:
- 下载适用于您的 PHP 客户端
平台的 SQL Server ODBC 驱动程序。(需要注册。)如果 SQL Server ODBC 驱动程序当前不适用于您的平台,请检查
ODBC-ODBC 桥客户端平台列表。ODBC-ODBC Bridge 是
Easysoft的替代 SQL Server 解决方案,您可以从该站点下载。 - 在安装了 PHP 的计算机上安装 SQL Server ODBC 驱动程序并获得许可。有关安装说明,请参阅 ODBC 驱动程序文档。参考文档查看需要设置哪些环境变量
(LD_LIBRARY_PATH, LIBPATH, LD_RUN_PATH, SHLIB_PATH depending on the driver, platform and linker).
在其中创建一个
/etc/odbc.ini
连接到SQL Server database
要从 PHP 访问的 ODBC 数据源。例如,此 SQL Server ODBC 数据源连接到为 Northwind 数据库提供服务的 SQL Server Express 实例:- 使用 isql 测试新数据源。例如:
cd /usr/local/easysoft/unixODBC/bin
./isql -v MSSQL-PHP
- 使用 isql 测试新数据源。例如:
[MSSQL-PHP] Driver = Easysoft ODBC-SQL Server Server = my_machine\SQLEXPRESS User = my_domain\my_user Password = my_password
[MSSQL-PHP] Driver = Easysoft ODBC-SQL Server Server = my_machine\SQLEXPRESS User = my_domain\my_user Password = my_password
Please copy and paste this script and execute this
请复制并粘贴此脚本并执行此操作
<?
/*
PHP MSSQL Example
Replace data_source_name with the name of your data source.
Replace database_username and database_password
with the SQL Server database username and password.
*/
$data_source='data_source_name';
$user='database_username';
$password='database_password';
// Connect to the data source and get a handle for that connection.
$conn=odbc_connect($data_source,$user,$password);
if (!$conn){
if (phpversion() < '4.0'){
exit("Connection Failed: . $php_errormsg" );
}
else{
exit("Connection Failed:" . odbc_errormsg() );
}
}
// This query generates a result set with one record in it.
$sql="SELECT 1 AS test_col";
# Execute the statement.
$rs=odbc_exec($conn,$sql);
// Fetch and display the result set value.
if (!$rs){
exit("Error in SQL");
}
while (odbc_fetch_row($rs)){
$col1=odbc_result($rs, "test_col");
echo "$col1\n";
}
// Disconnect the database from the database handle.
odbc_close($conn);
?>
- Replace
data_source_name, database_username and database_password
with your SQL Server ODBC data source, login name and password. To run the script under Apache, save the file below your Apache web server's document root directory
. For example, /var/www/apache2-default/php-mssql-connection.phtml. Then view the file in a web browser:
http://localhost/php-mssql-connection.phtml
- If your web browser is not running on the same machine as the web server, replace localhost with the web server's host name or IP address.
To run the script from the command line, save the file.
For example, /tmp/php-mssql-connection.php. Then run $ php /tmp/php-mssql-connection.php.
- 替换
data_source_name, database_username and database_password
为您的 SQL Server ODBC 数据源、登录名和密码。 要在 Apache 下运行脚本,请将文件保存在 Apache Web 服务器的文档根目录下
. For example, /var/www/apache2-default/php-mssql-connection.phtml. Then view the file in a web browser:
http://localhost/php-mssql-connection.phtml
- 如果您的 Web 浏览器与 Web 服务器不在同一台机器上运行,请将 localhost 替换为 Web 服务器的主机名或 IP 地址。
要从命令行运行脚本,请保存文件。
例如,/tmp/php-mssql-connection.php。然后运行 $ php /tmp/php-mssql-connection.php。