Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel migration cannot find driver when using sqlsrv database in windows

I am using sqlsrv database connection in my project as I need to connect to Microsoft SQL Database.

I have successfully installed the sqlsrv driver because I can connect to the Database to retrieve data.

But when I try to do the Laravel Migration, it shows an error:

Illuminate\Database\QueryException  : could not find driver (SQL: select * from sysobjects where type = 'U' and name = migrations)

Below is my .env

DB_CONNECTION=sqlsrv
DB_HOST=**********.database.windows.net
DB_PORT=1433
DB_DATABASE=****************_4cd1_9d18_2a7d9ddbcd13
DB_USERNAME=***************_4cd1_9d18_2a7d9ddbcd13_ExternalWriter
DB_PASSWORD=***************

php.ini

extension=php_xmlrpc.dll
extension=php_xsl.dll
extension=php_pdo_sqlsrv_7_nts_x64.dll
extension=php_pdo_sqlsrv_7_nts_x86.dll
extension=php_pdo_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_ts_x86.dll
extension=php_pdo_sqlsrv_71_nts_x64.dll
extension=php_pdo_sqlsrv_71_nts_x86.dll
extension=php_pdo_sqlsrv_71_ts_x64.dll
extension=php_pdo_sqlsrv_71_ts_x86.dll


extension=php_sqlsrv_7_nts_x64.dll
extension=php_sqlsrv_7_nts_x86.dll
extension=php_sqlsrv_7_ts_x64.dll
extension=php_sqlsrv_7_ts_x86.dll
extension=php_sqlsrv_71_nts_x64.dll
extension=php_sqlsrv_71_nts_x86.dll
extension=php_sqlsrv_71_ts_x64.dll
extension=php_sqlsrv_71_ts_x86.dll
like image 961
Lim Socheat Avatar asked Jan 02 '23 15:01

Lim Socheat


2 Answers

How to use SQL Server DLL files with PHP 7.2 version on xampp

https://github.com/Microsoft/msphpsql/releases

To download Windows DLLs for PHP 7.1 or above from the PECL repository, please go to the SQLSRV or PDO_SQLSRV PECL page.

https://pecl.php.net/package/sqlsrv/5.6.1/windows

https://pecl.php.net/package/pdo_sqlsrv/5.6.1/windows

NOTE: Do not forget to remove 'php_' prefix when you add extension dll filename in php.ini file. eg.

extension=pdo_sqlsrv
extension=sqlsrv

Do not change actual filename which you put in /xampp/php/ext/ directory.

"7.2 Thread Safe (TS) x86" worked for me for 'sqlsrv' and 'pdo_sqlsrv' extensions.

Restart xampp or apache then you can see enabled 'pdo_sqlsrv' extension when you print phpinfo() in a test php file

enter image description here

It was very hard to find this solution. I hope, this will also help you. All the best :)

like image 52
Kamlesh Avatar answered Jan 05 '23 14:01

Kamlesh


You may need to upgrade your PHP version to PHP 7.1. Now make sure that the files config/database.php and .env are configured properly.

See this one: https://laracasts.com/discuss/channels/general-discussion/connect-laravel-to-microsoft-sql

like image 43
Eazy Sam Avatar answered Jan 05 '23 14:01

Eazy Sam