Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

connect and query to a remote MSSQL server via PHP exec

Posted on 2014-04-21
4
Medium Priority
?
1,577 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 84

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 54

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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

879 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