Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

saluei's avatar

Connection to MS SQLServer

I configure php.ini to connect to sqlserver, added needed extension :

extension=php_sqlsrv_74_nts_x64.dll

extension=php_pdo_sqlsrv_74_nts_x64.dll

and extension loaded it is OK , MS Sql server installed and TCP port is open,

.env file and database.php file configed like these:

'sqlsrv' => [ 'driver' => 'sqlsrv', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '1433'), 'database' => env('DB_DATABASE', 'xxx'), 'username' => env('DB_USERNAME', 'xxx'), 'password' => env('DB_PASSWORD', 'xxx'), 'charset' => 'utf8', 'prefix' => '', 'prefix_indexes' => true, ],

DB_CONNECTION=sqlsrv DB_HOST=localhost DB_PORT=1433 DB_DATABASE=xxx DB_USERNAME=xxx DB_PASSWORD=xxx

but this is error encountered when I want to select something : "driver not found"

or if I run "php artisan migrate" I have this ERROR :

Illuminate\Database\QueryException

could not find driver (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

at C:\inetpub\test1\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671 667| // If an exception occurs when attempting to run a query, we'll format the error 668| // message to include the bindings with SQL, which will make this exception a 669| // lot more helpful to the developer instead of just the database's errors. 670| catch (Exception $e) { 671| throw new QueryException( 672| $query, $this->prepareBindings($bindings), $e 673| ); 674| } 675|

C:\inetpub\test1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 PDOException::("could not find driver")

C:\inetpub\test1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 PDO::__construct()

thank in advance for any help.

0 likes
5 replies
saluei's avatar

thank's jIrdw, but I do everything said in link you suggest, and installed everything that mentioned [SQL Server ODBC driver and C++ redistribution ] but error exist, and problem do not solved

saluei's avatar

thank's jlrdw for reply

I changed DB_HOST=localhost to DB_HOST=[computer name/sql server instance]

and problem solved , any way I do not know any reason for this

Kumaravel's avatar

Check whether the drivers have been reflected by calling phpinfo() in your PHP code and loading that file in the browser. Then if you can find the sqlsrv driver installed, then it's nothing wrong with the installation. If it's not showing, then there is an issue with the installation.

Also, make sure that you have downloaded and added those .dll files to the folder where other extensions are located.

Because Installing PHP won't have the sqlsrv dll extensions as pre-installed.

Please or to participate in this conversation.