• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2556
  • Last Modified:

connect to SAP from PHP

Hello experts!
I need to connect to our SAP server from our PHP/MySQL xampp server.
Im using this
$ServerIp= "192.168.8.251:30000";
#Also tried:  
#$ServerIp= "192.168.8.251,30000";
$dbh=mssql_connect($ServerIp,"user","**********");

and im getting a "unable to connect to server: .... "

If I telnet server ip, port, the sql answers.  So there is no port mistake., maybe the string

Also, user, password strings are correct. (used in other programs)
+ How can I test (using other program) the connection strings are correct ?
+ What do you recommend me to use

Thanks in advance!
0
T1Tower
Asked:
T1Tower
  • 12
  • 6
  • 2
1 Solution
 
mankowitzCommented:
mssql_connect is to connect to microsoft SQL Server. I think you want something like this http://it.toolbox.com/blogs/php-sap-dev/getting-started-with-php-and-sap-8354
0
 
T1TowerAuthor Commented:
Yes Mankowitz, our sap is running on mssql.
0
 
mankowitzCommented:
ok, so if you are using windows, your serverip should be of the form "hostname,port"

$ServerIp= "192.168.8.251,30000";

Some advice from the php site

Use the Microsoft SQL Server Driver for PHP!

1) Download from http://tiny.cc/fkGzf
2) Place php_sqlsrv_ts.dll in your php extensions folder.
3) Enable php_sqlsrv_ts.dll in your php.ini -> extension=php_sqlsrv_ts.dll
4) Follow the documentation and api reference at http://msdn.microsoft.com/en-us/library/cc296152%28SQL.90%29.aspx

if you don't use microsoft, there is an alternative at http://www.freetds.org/
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Shinesh PremrajanEngineering ManagerCommented:
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number

$server = 'KALLESPC\SQLEXPRESS';

// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'phpfi');

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}

Hope this helps
0
 
T1TowerAuthor Commented:
Thank you Mankowitz, I will try your suggestion.
BTW, the link you provided is dead. I tried this one, is this ok ?
http://www.microsoft.com/downloads/en/confirmation.aspx?displaylang=en&FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9
0
 
T1TowerAuthor Commented:
Thank you shinug, I will check the format you mention.
0
 
T1TowerAuthor Commented:
mankowitz:
I tried your suggestion, with microsoft driver

in PHP.INI
extension=php_mssql.dll
extension=php_sqlsrv_52_ts_vc6.dll

I am using this php, with no luck yet.

$dbh=mssql_connect("192.168.9.251","USERNAME","PASSWORD");

Funny thing is that I can  connect to the server using excel

Any ideas ?
0
 
T1TowerAuthor Commented:
shinuq:

I tried several options and no luck
IP
IP:30000
IP:1433
MySERVERNAME:30000
MySERVERNAME:1433

Where can I get the SQL server instance name ?   The guy who set it up is not cooperating with us.

excel works fine with the ip address.
0
 
Shinesh PremrajanEngineering ManagerCommented:
try to telnet the ip address and the port something like in the command prompt

> telnet IPaddress port

If the port and IP are correct then it wont show any error message, its a negative test. Like if the connection fails then you will get a error message, so you will confirm that the things are not working..

similarly you can try this for any other application to confirm that the IP and port are correctly called from remote.

Hope this helps
0
 
T1TowerAuthor Commented:
Thank you shinug, telnet ipnumber 30000 does answer
tried the 1433 port and no luck.

Excel connects with the server ip address alone.  tcpview tells the connection has ben made to the server, but no port, instead says its been made to "ms-sql-s" in the port column

Im thinking this is something to do with php, not the server.
but what else could it be ?

Thanks in advance
0
 
T1TowerAuthor Commented:
Also, sqlsrv_connect does not work at all.
Im getting
 to undefined function sqlsrv_connect()

Dont know if that helps.
0
 
Shinesh PremrajanEngineering ManagerCommented:
you need to do this

<computer>\<instance name>
$server = 'GENR\SQLEXPRESS';

Else
$server = 'ipnumber,30000';

$link = mssql_connect($server.... , This one i think you already using, as mention in your post.

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}


Hope this helps





0
 
Shinesh PremrajanEngineering ManagerCommented:
ok to get the sql server instance name you need to have the

SQL server Management Studio Express, the client that connects to the SQL Server.

Another option i can see is to use create a DSN and use that in your PHP script.

$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);


Hope this helps
0
 
T1TowerAuthor Commented:
Thank you Shinuq

so far tried:  ( and remarked after failure)

  #$dbh=mssql_connect("192.168.8.251:30000",$usr,$pwd);
  #$dbh=mssql_connect("192.168.8.251:30000",$serverusr,$serverpwd);
  #$dbh=mssql_connect("192.168.8.251:30000",$usr,$pwd);
  #$dbh=mssql_connect("192.168.8.251:30000",$usr,$pwd);
  #mssql_connect("192.168.8.251:30000",$usr,$pwd);
  #mssql_connect("192.168.8.251:30000",$serverusr,$serverpwd);
  #$dbh=mssql_connect("192.168.8.251:30000",$serverusr,$serverpwd);
  #$dbh=mssql_connect("192.168.8.251:30000",$usr,$pwd);
  #$dbh=mssql_connect("192.168.8.251:30000",$usr,$pwd);  
  #$dbh=mssql_connect("192.168.8.251:30000",$usr,$pwd);
  #$dbh=mssql_connect("B1",$usr,$pwd);
  #$dbh=mssql_connect("B1/MSSQLSERVER",$usr,$pwd);
  #$dbh=mssql_connect("192.168.8.251",$usr,$pwd);
  #$dbh=mssql_connect("192.168.8.251:30000",$usr,$pwd);
  #$dbh=mssql_connect("192.168.8.251,30000",$usr,$pwd);
  $dbh=mssql_connect("B1\MSSQLSERVER",$usr,$pwd);
 
  if($dbh)
  {
    echo "connected";
  } else {
    echo "Not connected";
  }

I have sql server management studio, but dont see the server instance name, I got MSSQLSERVER from the eventviewer reports

trying odbc_connect
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);

says:
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][Administrador de controladores ODBC] No se encuentra el nombre del origen de datos y no se especificó ningún controlador predeterminado, SQL state IM002 in SQLConnect in E:\....\sap.conn.php on line 36

translated says:
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC driver manager] No data source name found and no default controller specified, SQL state IM002 in SQLConnect in E:\....\sap.conn.php on line 36

I Think i need to enable odbc in the client machine.  im running all this from the client machine ( the xampp server )

What do you think ?

Thanks in advance




0
 
Shinesh PremrajanEngineering ManagerCommented:
control panel > administrative task  >> odbc drivers.

You need to create a DSN here, system DSN, this will connect to the SQL Server.

that DSN name you need to define in the odbc_connect funtion like

odbc_connect ( DSNNAMEHERE , user , pass);

Hope this helps
0
 
T1TowerAuthor Commented:
I changed "SQL Server Native Client 10.0" to  "Sql Server" and it worked.  SQL Server appeared in the odbc drivers in the client machine, just minutes  before your  02/23/11 22:01 posting

THIS IS GREAT.

running some tests now...
0
 
T1TowerAuthor Commented:
Works great.

Thanks Shinuq!

I now need to code some MSSQL instead of MySQL.  Do you know where to get some good  language reference ?
0
 
T1TowerAuthor Commented:
Great
0
 
Shinesh PremrajanEngineering ManagerCommented:
The best place is the php.chm file, that u can get the function and the related function using the search, along with the examples of how to use it defined below it.

Good to hear that you finally go it working!!

Kul..

0
 
T1TowerAuthor Commented:
Thanks, basically the same, just some little differences in syntax
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 12
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now