We help IT Professionals succeed at work.

PHP and MSSQL Arrays and Variables

Joe Danyi
Joe Danyi asked
on
162 Views
Last Modified: 2017-03-07
Hello I am trying to learn how to connect PHP with MSSQL,
I currently am trying to load my username and password for my PHP to SQL login via calling a file like so:
$serverName = "Databaseserver";
$uid = file_get_contents("G:\s\s\uid.txt");  
$pwd = file_get_contents("G:\s\s\pwd.txt");  
$connectionInfo = [ "UID"=>$uid, "PWD"=>$pwd, "Database"=>"423" ];  

However I cannot seem to get it to connect with the above variables.
I can however connect by placing the user name and password like so:
$serverName = "Databaseserver";
$connectionInfo = array( "Database"=>"423", "UID"=>"423", "PWD"=>"Password”);
$conn = sqlsrv_connect( $serverName, $connectionInfo);

Would it be possible to place the $uid and $pwd variables into the array?


I am using server 2012 R2,
SQL server 2008 ( I believe)
PHP 5.6 on IIS
Thank you in advance let me know if you need more info.
Comment
Watch Question

Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
You need to use the 'sqlsrv' driver to connect PHP to MS SQL Server.  I've written an article on this subject:  https://www.experts-exchange.com/articles/28391/PHP-and-Microsoft-SQL-Server.html    And here's the 'man' page for it:  http://php.net/manual/en/book.sqlsrv.php
Joe DanyiOwner

Author

Commented:
Yes i am using the sqlsrv.

In particular i am hoping you can help me with the way i am submitting data for authentication with the server?
Fixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.