N
N
NataliaCh2017-09-29 11:08:09
PHP
NataliaCh, 2017-09-29 11:08:09

What is the error when trying to connect to MS SQL via PDO_SQLSRV?

You need to configure the webserver to connect to the MS SQL database.
Wednesday: Windows NT 6.0, IIS 8.0, PHP 7.0.1
I did everything according to the instructions. I installed the php driver downloaded from the microsoft site ( php_pdo_sqlsrv_7_nts_x64.dll), added the extension to php.ini. I updated the server, the pdo_sqlsrv entry appeared in phpinfo.
Run the db connection script

$serverName = "имя сервера";   
$database = "имя базы";  
$uid = "имя пользователя";
$pwd = "пароль";

$conn = new PDO( "sqlsrv:server=$serverName;database=$database", $uid, $pwd);

An error was thrown:
PHP Fatal error: Uncaught PDOException: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server.
Installed ODBC Driver 11.
Run the script again and error:
SQLSTATE[28000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login error for user 'username' The
account is working. Through it, without any problems, I connect to the database via ssms.
And the browser for some reason does not always give this particular error. More often like this:
PHP Fatal error: Invalid handle returned
It's not clear something is wrong with the account or with the server settings? Uchetka, by the way, composite: NAME_LOCAL_NETWORK\user_name. Maybe because of this slash some problems?
Please help me figure it out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2017-09-29
@NataliaCh

NETWORK_NAME\user_name

win authorization implies a user as domain_name/user_name_in_domain or computer_name/user_name_on_computer
, well, it is desirable to specify the database server in full as server[.domain]/instance,
as a rule, MS prefers the backslash "\", but also accepts direct ones.
but in $uid - I would look to see if there is something like "server<carriage return>mm" instead of "server\mmm"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question