Solved

connect and query to a remote MSSQL server via PHP exec

Posted on 2014-04-21
4
1,434 Views
Last Modified: 2014-04-27
I am trying to connect to a remote MSSQL server using the PHP exec(). I have shell access on the PHP server but not the ability to edit the server. The server does not have the correct PDO drivers or mssql_connect(). The only available option seems to be to run the remote query via exec(), unless someone else knows a way.  

I have the remote MSSQL location and it is open on port 1433. I normally work with MySQL and am not familiar with MSSQL.
0
Comment
Question by:phper
  • 2
4 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40013283
Need more info.  Connecting to MS SQL Server can be a little more difficult than MySQL.  The server where the SQL Server is running is obviously Windows.  What is the server where PHP is running?  If it is Linux, which version of Linux?  And what version of PHP?

Have you been given a remote TCP/IP login for the SQL Server?  For that matter, being "open on port 1433" does not actually mean that the SQL Server is accepting remote TCP/IP connections.  That has to be set up in the SQL Server configuration.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40013303
I use pdo like this for mssql on windows

$db_host = "localhost"; 
$db_name = "database_name";       
$db_user = "db_username";
$db_word = "myPassword";

$uid="mickeymouse"
$user_password_hash="40203abe6e81ed98cbc97cdd6ec4f144"

$query_check_user_name = $db->prepare('SELECT ID, UserName,   FROM dbo.tContacts WHERE UserName=:user_name AND PassWord=:password',array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$query_check_user_name->bindValue(':user_name', $uid, PDO::PARAM_STR);
$query_check_user_name->bindValue(':password', $user_password_hash, PDO::PARAM_STR);
$query_check_user_name->execute();
$res = $query_check_user_name->rowCount();

Open in new window

0
 

Author Comment

by:phper
ID: 40015043
padas: The server does not have the correct PDO driver and they cannot be installed.

D. Baldwin: The server running PHP is a somewhat restrictive shared host. They did give me shell access but did not install the correct PDO drivers. I am trying to run a query on a remote MSSQL database and retrieve the response to the query. The server running PHP is a LAMP server (PHP Version 5.3.27. PDO Drivers: sqllite, sqllite2 & mysql), but I do not know what version of Linux. The remote database information is not entirely known too. The remote DB admins just said that they approved the PHP server's IP for access. I have the URL and the port (1433) for the remote MSSQL db and they will provide me wit the user/pass/dbname once I am ready. Thank you for your help. I can provide any traditional information you may need.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40015812
This is sounding like a lost cause from the start.  MS SQL, like MySQL, requires a driver to access it.  There is no text mode or telnet connection that you can make.  PDO Requires a correct driver for the database you are accessing.  And, like MySQL, the user/pass/dbname are also Required to make the connection.

Since you don't have the drivers or the information, I don't see how you can succeed with this project.  The things that are missing are not things that you can guess at and get right.

http://us3.php.net/manual/en/ref.pdo-dblib.php
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
The viewer will learn how to dynamically set the form action using jQuery.

776 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