我在PHP页面中使用odbc_connect()
连接到HANA数据库。我在本地运行时工作正常。
我将相同的PHP页面上传到服务器,我收到此错误:
Fatal error: Call to undefined function odbc_connect()
代码:
$connect = odbc_connect("Team6DataSource", "TEAM6", "Password1", SQL_CUR_USE_ODBC);
Team6DataSource =数据源名称。
ip address = 54.217.234.218
任何人都可以帮帮我吗? 感谢
答案 0 :(得分:6)
我只是通过谷歌获取this instruction这对你真有帮助。
(LD_LIBRARY_PATH, LIBPATH, LD_RUN_PATH,
SHLIB_PATH depending on the driver, platform and linker).
在/etc/odbc.ini
中创建连接到的数据源
您想要从PHP访问SQL Server database
。例如,这个
SQL Server ODBC数据源连接到SQL Server Express实例
为Northwind数据库提供服务:
cd /usr/local/easysoft/unixODBC/bin
强> ./ isql -v MSSQL-PHP
[MSSQL-PHP] Driver = Easysoft ODBC-SQL Server Server = my_machine\SQLEXPRESS User = my_domain\my_user Password = my_password
请复制并粘贴此脚本并执行此
<?
/*
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 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
要从命令行运行脚本,请保存文件。
例如, /tmp/php-mssql-connection.php。然后运行$ php /tmp/php-mssql-connection.php。
答案 1 :(得分:0)
下载this,将.dll
复制到PHP文件夹,然后在php.ini
文件中添加:
extension=php_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_nts_x64.dll