N
N
neeil2015-10-30 10:38:37
PHP
neeil, 2015-10-30 10:38:37

How to setup connection to ms sql via PDO class?

I do this $DBH = new PDO("mssql:host=localhost;dbname=health", $user, $pass);
in response I get only
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in D:\Projects\ZInfo\ZInfo-App-IsraelDieta\htdocs\site.ru\index2.php:5 ​​Stack trace: #0 D:\Projects\ZInfo\ZInfo-App-IsraelDieta\htdocs\site.ru\index2.php(5): PDO->__construct('mssql:host=SIRI...', '-----', '------...') #1 {main} thrown in D:\Projects\ZInfo\ZInfo-App-IsraelDieta\htdocs\site.ru\index2.php on line 5

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Max, 2015-10-30
@AloneCoder

php.net/manual/en/ref.pdo-sqlsrv.php

A
Aleksey Ratnikov, 2015-10-30
@mahoho

If you are on Windows (judging by the paths), then you need to install SQL Server Native Client x64 or x86 , depending on the platform. Then install the sqlsrv driver itself (do not forget to read the README, where it says which version of php which extension to connect to).
Then use the following as your DSN:

$dsn = 'sqlsrv:server=your-sqlserver-host.com;Database=db_name';
$pdo = new PDO($dsn, $username, $password);

N
neeil, 2015-10-30
@neeil

4bdd8e4b6726455e82a18aeaba88901c.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question