Смотрим список процессов:
C:\Users\leon>tasklist Имя образа PID Имя сессии № сеанса Память ========================= ======== ================ =========== ============ ... sqlservr.exe 2408 Services 0 1 505 316 КБ ... C:\Users\leon>netstat -ano Имя Локальный адрес Внешний адрес Состояние PID ... TCP 127.0.0.1:1434 0.0.0.0:0 LISTENING 2408 ...
Таким образом убеждаемся, что сервер запущен и слушает порт 1434
Проверяем разрешен ли TCP/IP для SQL-сервера:
SQL Server Configuration Manager -> Network Configuration -> Protocols -> TCP/IP enabled
Документация драйвера MSSQL для PHP от Microsoft тут - http://msdn.microsoft.com/ru-ru/library/ee229547%28v=SQL.10%29.aspx
Качаю и ставлю драйвер MSSQL для PHP тут -
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9
Системные требования для установки драйвера - http://msdn.microsoft.com/ru-ru/library/cc296170%28v=SQL.90%29.aspx
Для PHP 5.3.x в php.ini добавляю следующее (dll положил в ext):
... [PHP_SQLSRV] extension=php_sqlsrv_53_nts_vc9.dll ...
Далее пытаюсь подключиться (подробности http://msdn.microsoft.com/ru-ru/library/cc296161%28v=sql.90%29.aspx):
/* Connect to the local server using Windows Authentication and specify the AdventureWorks database as the database in use. To connect using SQL Server Authentication, set values for the "UID" and "PWD" attributes in the $connectionInfo parameter. For example: $connectionInfo = array("UID" => $uid, "PWD" => $pwd)); */ $serverName = "(local)"; $connectionInfo = array("Database" => "MyMSDb"); $conn = sqlsrv_connect($serverName, $connectionInfo); if( $conn ) { echo "Connection established.\n"; } else { echo "Connection could not be established.\n"; die(print_r( sqlsrv_errors(), true)); } //----------------------------------------------- // Perform operations with connection. //----------------------------------------------- /* Close the connection. */ sqlsrv_close($conn);
Получаю ошибку:
The SQL Server Driver for PHP requires the SQL Server 2008 Native Client ODBC Driver (SP1 or later) to communicate with SQL Server. That ODBC Driver is not currently installed. Access the following URL to download the SQL Server 2008 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
Клиент стоял для MSSQL Server 2005, значит качаем и ставим для 2008
http://download.microsoft.com/download/0/E/6/0E67502A-22B4-4C47-92D3-0D223F117190/sqlncli.msi
Запускаю скрипт - ошибка:
... [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'leon-PC\leon' ...Клиент работает - это хорошо, авторизация не проходит ...
Вместо MyMSDb ставим имя реальной базы данных и на локальной машине подключение проходит.
Connection established.
Комментариев нет:
Отправить комментарий