Solved

connect and query to a remote MSSQL server via PHP exec

Posted on 2014-04-21
4
1,460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

697 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