Call to undefined function odbc_connect() message while connecting SAP Hana database - 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()
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

I just go through in google get this instruction this 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 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);
?>
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.
further more Details Refer this LINK

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

Related

Setting up a local call to DB with an online PHP file - trouble connecting

Trying to figure out how to connect to a local SQL Server with an online PHP file. However I am getting connection errors.
Warning: mysql_connect() [function.mysql-connect]: [2002] No
connection could be made because the target machine actively refused
it. (trying to connect via tcp://localhost:xxxx) in
E:\web\example.com\uploads\readDB.php on line 8
In particular I am having trouble trying to specify if, and where, I do the connection to the PC and then to the database with any associated passwords.
My current connection looks like this
mysql_connect("localhost","the_sql_server_name\SQLEXPRESS","mysql");
mysql_select_db("ACME") or die(mysql_error());
$data = mysql_query("SELECT * FROM TradingAccount")
or die(mysql_error());
My server is run locally (sql server studio management 2012), and I am trying to connect to its specific DB called ACME, from the table TradingAccount.
Can someone show me how to connect to this local table successfully with PHP? I use Windows Authentication at the moment when I run the server as well, in case that matters.
I haven't been able to find any useful resources, and I have only ever used PHP to connect to online DB's as well, nothing locally before.
Your Problem is in this line:
mysql_connect("localhost","the_sql_server_name\SQLEXPRESS","mysql");
You wrote the_sql_server_name\SQLEXPRESS there. I don't understand why. The syntax of the method is:
mysql_connect("hostname", "username", "password");
For more information, visit the PHP manual entry for mysql_connect.

PHP, can't connect to the MySQL server

What might be the reason of the following problem.
PHP function mysql_connect() works fine if I execute it from
command line (php -r "mysql_connect('127.0.0.1', 'db_user', 'db_pass');").
The same call with the same parameters fails for PHP running as an Apache module.
MySQL server is running remotely, connection to it is forwarded using SSH: ssh -fN -L 3306:localhost:3306 remote_host
Any ideas what might be wrong?
You'll want to be looking at using MySQLi or PDO as the older MySQL functions are deprecated.
This should help get you started:
<?php
//establish conection
$link = mysqli_connect("host","user","pass","bd") or die("Error: " . mysqli_error($link));
$query = "SELECT name FROM mytable" or die("Error: " . mysqli_error($link));
//execute query
$result = $link->query($query);
//display information
while($row = mysqli_fecth_array($result)) {
echo $row["name"] . "<br>";
}
?>
Based on your question and details, I would say that the MySQL server is refusing to connect to your web server (where ever it is) because the connection is not secure (in one fashion or another). If you want to connect via the PHP module in Apache as easily as you do from the command line, set up your connection so that all encryption/ tunneling issues are resolved. That's what I would do.
However, make sure the following line is correct..
mysql_connect('127.0.0.1', 'db_user', 'db_pass');"
Are you pointing to the correct server? I thought you said that the MySQL server was remote. This line suggests that you are attempting to connect to a local, imaginary MySQL server that is running on the same machine as the web server. Try getting the IP or domain name of the MySQL server and use that instead (in your web code, that is).

localhost, Microsoft SQL and php

I just started learning PHP and MySQL, and I got stuck when trying to connect to my database from a PHP block. I have installed XAMPP and SQL Server Express 2012 on my machine. My server name is RAFAL-MAC and I selected 'Windows Authentication.'
I have a simple HTML page with PHP code in a file called search.php
the PHP code is
<?php
$con = mysql_connect('RAFAL-MAC','RAFAL-MAC\Rafal','');
if (!$con)
{
die( 'Could not connect: ' . mysql_error() ) ;
}
mysql_select_db("one", $con) or die(mysql_error());
?>
When I go to localhost:8080/search.php I get the following warning:
Warning: mysql_connect(): Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server in C:\xampp\htdocs\search_submit.php on line 11
Could not connect: Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
I tried searching similar problems online, but all of the threads are about remote connections. I am just trying to connect to my local SQL server.
Any hints? I apologize for any missing information. Thanks! :)
EDIT:
I changed the server name to 'localhost'
Now I am getting this:
Access denied for user ''#'localhost' to database 'one'
Since you'd like to connect to SQL Server Express 2012, all functions beginning with mysql* will fail - since these functions speak to MySQL servers.
Please install Microsoft's MS SQL Server driver pack found here. From this page:
Perform the following steps to download and install the Microsoft
Drivers for PHP for SQL Server:
Download SQLSRV30.EXE to a temporary directory
Run SQLSRV30.EXE
When prompted, enter the path to the PHP extensions directory
After extracting the files, read the Installation section of the SQLSRV30_Readme.htm file for next steps
People in Microsoft's PHP driver forum should easily be able to answer your question, in case you still have problems after the installation of the driver.
Additionally, if connecting to the local machine, try to use these addresses:
localhost
127.0.0.1
These two addresses always reference the local machine.

Cannot connect to SQL SERVER 2000

I am using php 5.3.1 to connect to my SQL SERVER 2000 on remote machine. I use Windows XP.
On using simple program like this:
$conn = mssql_connect("VBNET","sa","mypass") or die ( 'Can not connect to server' );
I get following error:
Warning: mssql_connect() [function.mssql-connect]: message: Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server connection. (severity 14) in C:\wamp\www\Mssql\test.php on line 8
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: VBNET in C:\wamp\www\Mssql\test.php on line 8
Can not connect to server
I enabled TCP/IP and named pipes in my SQL SERVER and restarted it. Also its Authentication is set to Mixed Mode Authentication.
I can see my server through MS SQL Server Management Studio. So what am I missing here ?
Thanks in advance.
P.S. I have another server in SQL SERVER 2008 to which I can easily connect with the same above mentioned connection string.
EDIT: According to this post, I fired sqlcmd -S np:\\VBNET\pipe\sql\query -U sa in cmd and entered the password and that worked !!! So now what could be the problem. I am at my wits end...please help !!
If you can connect using SSMS, then copy the connection exactly, i.e. make sure you specify a named instance (e.g. 'VBNET\SQLSERVER'). Open SSMS, on the server node on the left side right click and select 'Properties'.
If you have SQL 2008 running on the same machine it is most likely that SQL 2008 uses the default instance and SQL 2000 a named instance.
What also could help, i.e. make testing simpler is to create an empty UDL file (e.g. 'TEST.UDL'). An empty text file should do. Then double click on it, select the provider and play around with the settings. You can always test the connection using the 'Test connection' button. I use this trick when I have to connect from a customer PC for the first time.

remote mssql 2008 connection issue

I am having issues connecting to a mssql server that is located on a network machine. I need to connect remotely through another domain example (abc.com) not on the network to access data. This domain runs mysql if that makes any difference. I am trying to access the mssql server through this php script:
<?php
$server= 'ip address:port';
$user='user';
$password= 'pass';
$con = mssql_connect($server,$user,$password);
if (!$con)
{
die('Could not connect:' . mssql_get_last_message() );
}
else{ echo 'connected';
}
I run this script through the shell on abc.com and I get:
mssql_connect(): Unable to connect to server:
I have gone through several tutorials to enabling tcp/ip access through the sql server config manager as well as allowing the specific port through the firewall.
What are some other things I should try or steps I am missing here.
Also: the ip address I am using is the one I found in the sql server config manager-> protocols for SQLEXPRESS->tcp/ip_>ip addresses->IP2->ip adress it is the correct ip address? Where can I find it if not? I am not using the localhost 127.0.0.1
In short to successfully execute the cmd.
config:
(2 instances of SQL // SQL2005 + 2008 Express instance on the remote machine, which refuses to install Management Studio 2008.
1. Enable TCP/IP Protocol
2. Enable Named Piptes
3. started sqlcmd Utility with -s \SQLEXPRESS to get the right sever-instance
C:\Program Files\Microsoft SQL Server\100\Tools\Binn
4. Go to SMSS and local sql instance properties -> Connections -> check "Allow remote connections to this server" and run this script.
EXEC sys.sp_configure N'remote access', N'1'
GO
RECONFIGURE WITH OVERRIDE
GO
Here the link for the info from Msdn:
http://msdn.microsoft.com/en-us/library/ms162773.aspx
http://msdn.microsoft.com/en-us/library/ms162816.aspx
Thanx

Categories