Link to home
Start Free TrialLog in
Avatar of T1Tower
T1Tower

asked on

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!
Avatar of mankowitz
mankowitz
Flag of United States of America image

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
Avatar of T1Tower
T1Tower

ASKER

Yes Mankowitz, our sap is running on mssql.
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/
// 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
Avatar of T1Tower

ASKER

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
Avatar of T1Tower

ASKER

Thank you shinug, I will check the format you mention.
Avatar of T1Tower

ASKER

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 ?
Avatar of T1Tower

ASKER

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.
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
Avatar of T1Tower

ASKER

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
Avatar of T1Tower

ASKER

Also, sqlsrv_connect does not work at all.
Im getting
 to undefined function sqlsrv_connect()

Dont know if that helps.
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





ASKER CERTIFIED SOLUTION
Avatar of Shinesh Premrajan
Shinesh Premrajan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of T1Tower

ASKER

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




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
Avatar of T1Tower

ASKER

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...
Avatar of T1Tower

ASKER

Works great.

Thanks Shinuq!

I now need to code some MSSQL instead of MySQL.  Do you know where to get some good  language reference ?
Avatar of T1Tower

ASKER

Great
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..

Avatar of T1Tower

ASKER

Thanks, basically the same, just some little differences in syntax
Thanks.