连接SAP Hana数据库时调用未定义函数odbc_connect()消息 [英] Call to undefined function odbc_connect() message while connecting SAP Hana database
问题描述
我在PHP页面中使用odbc_connect()
连接到HANA数据库.当我在本地运行它时,它工作正常.
我将相同的PHP页面上传到服务器,并且出现此错误:
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:
Fatal error: Call to undefined function odbc_connect()
代码:
$connect = odbc_connect("Team6DataSource", "TEAM6", "Password1", SQL_CUR_USE_ODBC);
Team6DataSource =数据源名称.
Team6DataSource = datasource name.
ip地址= 54.217.234.218
ip address = 54.217.234.218
有人可以帮助我吗? 谢谢
Can any one please help me? Thanks
推荐答案
我刚刚在Google中经历了该说明这对您真的很有帮助.
I just go through in google get this instruction this is really helpful for you.
- 下载适用于您的PHP客户端的SQL Server ODBC驱动程序
平台.(需要注册.)如果SQL Server ODBC驱动程序 当前不适用于您的平台,请检查
的列表 ODBC-ODBC桥客户端平台. ODBC-ODBC桥是一个
Easysoft的替代SQL Server解决方案,您可以 从此站点下载. - 在以下计算机上安装和许可SQL Server ODBC驱动程序
PHP已安装.有关安装说明,请参见ODBC驱动程序
文档.请参阅文档以查看哪个环境
您需要设置
(LD_LIBRARY_PATH, LIBPATH, LD_RUN_PATH, SHLIB_PATH depending on the driver, platform and linker).
的变量
-
在
/etc/odbc.ini
中创建一个ODBC数据源,该数据源连接到 您要从PHP访问的SQL Server database
.例如这个 SQL Server ODBC数据源连接到SQL Server Express实例 为Northwind数据库提供服务:
- 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:
- 使用isql测试新数据源.例如:
cd /usr/local/easysoft/unixODBC/bin
- Use isql to test the new data source. For example:
cd /usr/local/easysoft/unixODBC/bin
./isql -v MSSQL-PHP
./isql -v MSSQL-PHP
[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);
?>
- 替换
data_source_name, database_username and database_password
与您的SQL Server ODBC数据源,登录名和密码. -
要在Apache下运行脚本,请将文件保存在Apache网站下方 服务器的文档根目录
. For example, /var/www/apache2-default/php-mssql-connection.phtml. Then view the file in a web browser:
- 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
要从命令行运行脚本,请保存文件.
To run the script from the command line, save the file.
例如, /tmp/php-mssql-connection.php.然后运行$ php /tmp/php-mssql-connection.php.
For example, /tmp/php-mssql-connection.php. Then run $ php /tmp/php-mssql-connection.php.
这篇关于连接SAP Hana数据库时调用未定义函数odbc_connect()消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!