Call to undefined function odbc_connect() message while connecting SAP HANA database
Asked Answered
C

3

3

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

The code:

$connect = odbc_connect("Team6DataSource", "TEAM6", "Password1", SQL_CUR_USE_ODBC);

Team6DataSource = datasource name.

ip address = 54.217.234.218

Can any one please help me? Thanks

Cystocele answered 25/7, 2013 at 13:52 Comment(8)
do you check php.ini file ?Bannerol
sounds like you need to define odbc_connect :\Sandasandakan
if it is running on the remote server then how could i change it?Cystocele
please read this:clearfoundation.com/component/option,com_kunena/Itemid,232/…Bannerol
how can i define odbc_connect? :)Cystocele
do you connect in PHP while you can connect by using odbc_connect functionBannerol
Hi VIVEK-MDU the post you sent me it says it is missing include file or something. If that so then how come it is working perfect while i am running locally?Cystocele
Hi @ron...Read this article how to connect ODBC for live database phphelp.com/tutorial/… and you can call simple function odbc_connectBannerol
B
6

I just go through in google get this instruction this is really helpful for you.

  1. 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.
  2. 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).
  3. Create an ODBC data source in /etc/odbc.ini that connects to the SQL 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

[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);
?>
  1. Replace data_source_name, database_username and database_password with your SQL Server ODBC data source, login name and password.
  2. 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
    
  3. 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.
  4. 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.

further more Details Refer this LINK

Bannerol answered 25/7, 2013 at 14:49 Comment(0)
I
0

Download this, copy the .dll to PHP folder and in the php.ini file add:

extension=php_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_nts_x64.dll
Indefeasible answered 18/7, 2016 at 1:40 Comment(0)
V
0

windows
I downloaded apache 2.4 x64 zip; copied to: D:\Apache24-devel
https://www.apachelounge.com/download/
I downloaded php 8.3 threadsafe x64 zip; copied to D:\php-8-ts

Mind, in paths below I use "/..." without drive letter "D:" because I installed/extracted Apache and PHP on the same drive letter "D:".

In Apache conf/httpd.conf:

LoadModule php_module "/php-8-ts/php8apache2_4.dll"
AddHandler application/x-httpd-php .php

<FilesMatch \.(php$|php3)>
      SetHandler application/x-httpd-php
</FilesMatch>
# configure the path to php.ini
PHPIniDir "/php-8-ts/"

In php-8-ts/php.ini:

extension=odbc
extension_dir = "D:/php-8-ts/ext"

For configuration check (odbc) create:
D:/Apache24-devel/htdocs/dirX/phpinfo.php:

<?php
// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>

Check out:

> D:
> cd D:\Apache24-devel
> bin\httpd.exe

http://localhost/dirX/phpinfo.php

Vaucluse answered 23/2, 2024 at 7:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.