How to connect php and hana? - php

$driver = "HANADB";
$servername = "sercername";
$schema = "schemaname";
$username = "user";
$password = "XXXX";
$conn=odbc_connect("Driver={HANADB};Server=$servername;Schema=$db_name;",
$username, $password);}
I am using an odbc connection to try and connect to my hana schema. However, when i connect I get the following message
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source
name not found and no default driver specified, SQL state IM002 in SQLConnect in
I am not really sure as to where I am going wrong.

Did you install HANA clients already? Look here for some reference

If the HANA client is installed, the ODBC drivers are automatically added to your host.
May be you want to use the optional parameter cursor_type = SQL_CUR_USE_ODBC ??
Check: http://php.net/manual/en/function.odbc-connect.php
$conn = odbc_connect("", "", "", SQL_CUR_USE_ODBC);

Make sure you are using the 32bit ODBC Administrator to create your connection.
The 32bit ODBC admin is run from C:\Windows\SysWOW64\odbcad32.exe
The 64bit ODBC admin is run from C:\Windows\System32\odbcad32.exe
The 32 bit driver will show up in the list of available drivers as HDBODBC32.
Follow HANA Academy - Installing the 32bit HANA Client for more detailed explanation

Why not using Server Side JavaScript provided by SAP?
I recommend reading chapter 8 "Writing Server-Side JavaScript Code" of the SAP HANA Developer Guide

Related

SMS GATEWAY USING OZEKING MYSQL + PHP

I'm trying to configure an SMS GATEWAY USING OZEKING but I'm getting an error which has something to do with MYSQL ODBC DRIVER not being found. I have the driver installed on my Windows 10 machine and I'm not sure if I'm doing the right thing. In the OZEKING configuration I'm seeing this in the picture below:
The error I'm getting is :
12/16/2015 14:51:47 - INFO 6021: Connecting to database ODBC, DRIVER={MySQL ODBC 5.3 Driver};Server=localhost;Database=dbtest;UID=root;PWD=password#87;.
12/16/2015 14:51:47 - ERROR 6001: Database connection error: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified. ODBC;DRIVER={MySQL ODBC 5.3 Driver};Server=localhost;Database=dbtest;UID=root;PWD=password#87;
12/16/2015 14:51:47 - INFO 6026: Will try to reconnect to database in 20 seconds.
My question is what exactly am I doing wrong?
These parameters I'm entering Server=localhost;Database=dbtest;UID=root;PWD=password#87 are the ones I'm using to connect to my database, i.e:
$serverName = "localhost";
$userName = "root";
$password = "password#87";
$databaseName = "dbtest";
//create connection and select database by given data
$GLOBALS["connection"] = mysql_connect($serverName, $userName, $password);
if ($GLOBALS["connection"] == null)
{
echo mysql_error() . "<br>";
return false;
}
Anyone to assist me the correct way of doing things. Thanks.
ODBC drivers installed are 32-bit OR 64-bit, make sure you installed the correct architecture for your machine.
(install both to be safe)
Click Start and type "ODBC", you'll be given an option for your 32-bit and 64-bit sources, check them both and make sure your 5.3 driver is installed under both.

Using PDO's odbc to connect to a MSSQL server instance with Windows Authentication

I'm trying to connect to a MSSQL database using PDO with odbc. I'm aware that there's a package SqlSrv (but for some reason that package (.dll) won't load properly). So I found some documentation arguing it's also possible with PDO. In my PHP.ini I've enabled the extension php_pdo_odbc.dll and it loads fine.
My connection string looks like this:
$conn = new PDO(
'odbc:
Driver=SQL Server;
Server=MyServer\MyInstance;
Database=MyDatabaseName;
Trusted Connection=Yes;',
'MyWindowsUserName',
'MyWindowsPassword'
);
I've tried various properties (for example by prepending the domain to the username, switching with the authentication options User Id, UID, Password, PWD and Trusted Connection) but I keep getting the message
SQLSTATE[28000] SQLDriverConnect: 18456 [Microsoft][ODBC SQL Server
Driver][SQL Server]Login failed for user 'MyWindowsUserName'.
Any suggestions on how to connect to the database with my Windows Account? (that's the only way for me to connect to the database)
Try removing the username & password
$conn = new PDO(
'odbc:
Driver=SQL Server;
Server=MyServer\MyInstance;
Database=MyDatabaseName;
Trusted Connection=Yes;'
);
I have authenticated by Windows with following PHP statement:
This is my code:
$ Conn = new PDO ("odbc: Driver = {SQL Server}; Server=JAMILI-PC\SQLEXPRESS; null; null");
I am using Windows 2008.
I hope it solves your problem.

Connecting to MS SQL server from PHP

I am trying to connect to a SQL Server database from PHP but I'm having problems with the connection string. Here is a rundown of what I've tried and the effect it has had:
Running PHP 5.3.13, Apache 2.2.22, Windows 7, and SQL Server 2008 R2
I've installed SQL Server Native Client 11.0
I've dropped using MSSQL driver, using the SQLSRV driver instead.
Loaded these extensions in php.ini: extension=php_pdo_sqlsrv_53_ts.dll, extension=php_sqlsrv_53_ts.dll,
extension=php_pdo.dll.
phpinfo() shows these as active:
Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, phar, sqlsrv
PDO drivers mysql, odbc, sqlite, sqlsrv
sqlsrv support enabled
Connection code is as follows:
$serverName = "[servername]";
$connectionInfo = array( "Database"=>"[databasename]");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
The string is set up to use Windows authentication, which sqlsrv_errors() reports:
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user '[networkname]\[machinename]'
I have also tried this using my network id/pwd, resulting in
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user '[username]'
I do know that the database is up and functional, as I can connect and run queries without problem from the SQL Server client, and from sqlcmd. The SQL Client and the command line work when using my network/machine credentials. The command line client fails when I try with username/password. This would indicate that any PHP connection should use the Windows authentication to connect.
Someone in another thread suggested that changing permissions in a registry entry would work, but this did not help my issue. PHP 5.3 not recognizing Native Client to connect to MS SQL
I also had some success creating a system DSN. The connection test reports success:
Microsoft SQL Server Native Client Version 11.00.2100
Running connectivity tests...
Attempting connection
Connection established
Verifying option settings
INFO: A network alias was found for the DSN server. 'Protocol: DBMSSOCN; Address: [servername]' was used to establish the connection.
Disconnecting from server
TESTS COMPLETED SUCCESSFULLY!
I've searched extensively within stackoverflow.com, and the interwebs in general with no luck. Obviously the db connection is alive using other methods, but what is going wrong in my connection via PHP?
I got this solved by creating a new login using sql server authentication. I hope this helps somebody with similar issues.
SQLSRV uses the absence of a UID (uid==NULL || strlen(uid) ==0) to indicate that it should try set the "trusted connection" flag in the connection string, i.e. connect using the credentials implied by the execution context.
You can't pass a domain login and password (e.g. UID='MYDOMAIN\user') explicitly.
I had a weird compiler version issue with Microsoft's driver for PHP, and solved my connection problem with PHP's ODBC driver:
//$pdo = new PDO("sqlsrv:Server=$hostname;Database=$dbname;", $username, $password); // works with proper driver for PHP.
$pdo = new PDO("odbc:Driver={SQL Server};Server=$hostname;Database=$dbname;", $username, $password); // works with proper driver for ODBC and PHP ODBC.

MS SQL SERVER, PHP, PDO, ODBC: Login failed for user

I'm trying to connect using a string:
odbc:Driver={SQL Server Native Client 11.0};Server=(localdb)\v11.0;Database=test;uid=sa;password=123321;
Result: SQLSTATE[28000] SQLDriverConnect: 18456 [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'sa'.
When I try to connect using Windows ODBC Data Source Administrator the connection is successful.
What the problem might be in?
The network user 'sa' does not have permission to the Microsoft SQL Server.
The best way to provide network users access to Microsoft SQL Server is to create a Windows group (for example EGUSERS) and permit the Windows group Server Access at the Security Logins within Microsoft SQL Server.
Put all network users that need to have access to Microsoft SQL Server to the Windows group (EGUSERS).
Check if you have the right authentication mode set on the MSSQL Server:
https://msdn.microsoft.com/en-us/library/ms188670.aspx
Also you have two ways to connect to MSSQL through PHP/PDO by using the PHP_PDO_ODBC extension which uses the ODBC driver given in the connectionstring or use PHP_PDO_SQLSRV_xx_TS or PHP_PDO_SQLSRV_xx_NTS extension which you can find here (only for 32bit PHP!) https://www.microsoft.com/en-us/download/details.aspx?id=20098 or use the unofficial 64bit here http://robsphp.blogspot.nl/2012/06/unofficial-microsoft-sql-server-driver.html
connection string when using PHP_PDO_SQLSRV_xx_(N)TS extension:
$hostname='127.0.0.1';
$dbname='test';
$username='user';
$password='pw';
$dbDB = new PDO("sqlsrv:Server=$hostname;Database=$dbname", $username, $password);
connection string when using PHP_PDO_ODBC extension:
//use any of these or check exact MSSQL ODBC drivername in "ODBC Data Source Administrator"
$mssqldriver = '{SQL Server}';
$mssqldriver = '{SQL Server Native Client 11.0}';
$mssqldriver = '{ODBC Driver 11 for SQL Server}';
$hostname='127.0.0.1';
$dbname='test';
$username='user';
$password='pw';
$dbDB = new PDO("odbc:Driver=$mssqldriver;Server=$hostname;Database=$dbname", $username, $password);
When testing a simple query which returned 66 records using PHP_PDO_ODBC extension took ~500ms (for all three MSSQL ODBC drivers) but when using the 64bit(!) PHP_PDO_SQLSRV_TS it took ~5000ms. 10 times slower! Have not yet tried 32bit or the NTS variant.
My dev PC is Windows 7 SP1 using WAMPx64 PHP 5.5.12 and I used PHP_PDO_SQLSRV_55_TS

php apache (xampp) odbc connection issue

When I run apache (via xampp) as a standalone server not as a service (on Windows Server 2008)
with the following connection code everything works fine (username and password removed )
$server = "WMS";
$link = odbc_connect($server,'','');
if (!$link) {
die('Something went horribly wrong while connecting to MSSQL');
}else {echo('');}
If however I change apache to run as a service in Windows the connection breaks and I get the following error message
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in
C:\xampp\htdocs\Dev\well.php on line 30
Something went wrong while connecting to MSSQL
Please read documentation: http://uk.php.net/manual/en/function.odbc-connect.php
$server = "WMS"; suggests that you have ODBC alias/data source configured with that name. Error message clearly says that data source with such name (WMS) is not found. On Windows 7/Vista/XP/Server you can configure them at "Start -> Administrative Tools -> Data Sources (ODBC)" -- path can be different on older OS. In any case -- look for "Microsoft ODBC Data Source Administrator".
Instead of using alias, I would recommend (the way I always connect) to use full DSN name, e.g.
// Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008
$link = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
In this case everything is part of the script and no external dependencies.
BTW -- instead of using ODBC Functions, I would recommend using PDO & driver specially for MS SQL Server: PDO_SQLSRV -- http://uk.php.net/manual/en/ref.pdo-sqlsrv.php (or Microsoft SQL Server Driver for PHP if you prefer old procedural style -- http://uk.php.net/manual/en/book.sqlsrv.php )

Categories