Solved

connect to SAP from PHP

Posted on 2011-02-16
20
2,285 Views
Last Modified: 2013-12-13
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
Comment
Question by:T1Tower
  • 12
  • 6
  • 2
20 Comments
 
LVL 24

Expert Comment

by:mankowitz
ID: 34913468
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
 

Author Comment

by:T1Tower
ID: 34913729
Yes Mankowitz, our sap is running on mssql.
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 34913842
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
 
LVL 17

Expert Comment

by:shinuq
ID: 34914849
// 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
 

Author Comment

by:T1Tower
ID: 34950605
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
 

Author Comment

by:T1Tower
ID: 34950613
Thank you shinug, I will check the format you mention.
0
 

Author Comment

by:T1Tower
ID: 34967019
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
 

Author Comment

by:T1Tower
ID: 34967061
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
 
LVL 17

Expert Comment

by:shinuq
ID: 34967159
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
 

Author Comment

by:T1Tower
ID: 34967293
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:T1Tower
ID: 34967310
Also, sqlsrv_connect does not work at all.
Im getting
 to undefined function sqlsrv_connect()

Dont know if that helps.
0
 
LVL 17

Expert Comment

by:shinuq
ID: 34967321
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
 
LVL 17

Accepted Solution

by:
shinuq earned 500 total points
ID: 34967331
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
 

Author Comment

by:T1Tower
ID: 34967438
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
 
LVL 17

Expert Comment

by:shinuq
ID: 34967468
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
 

Author Comment

by:T1Tower
ID: 34967488
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
 

Author Comment

by:T1Tower
ID: 34967589
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
 

Author Closing Comment

by:T1Tower
ID: 34967591
Great
0
 
LVL 17

Expert Comment

by:shinuq
ID: 34967633
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
 

Author Comment

by:T1Tower
ID: 34975920
Thanks, basically the same, just some little differences in syntax
Thanks.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Salesforce.com is a cloud-based customer relationship management (CRM) system. In this article, you will learn how to add and map custom lead and contact fields to your Salesforce instance.
Read about achieving the basic levels of HRIS security in the workplace.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now