Solved

connect and query to a remote MSSQL server via PHP exec

Posted on 2014-04-21
4
1,424 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 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

18 Experts available now in Live!

Get 1:1 Help Now