Link to home
Start Free TrialLog in
Avatar of phper
phper

asked on

connect and query to a remote MSSQL server via PHP exec

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.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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

Avatar of phper
phper

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America 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