2
votes

My env file

DB_CONNECTION=sqlsrv
DB_HOST=DESKTOP-ATB1EFG
DB_DATABASE=frontdesk
DB_USERNAME=sa
DB_PASSWORD=something_secret123
DB_PORT=1433

I have tested with raw php as below, it is successfully connected and return "connected" string.

serverName = "DESKTOP-ATB1EFG";
    $connectionOptions = array(
        "Database" => "frontdesk",
        "Uid" => "sa",
        "PWD" => "something_secret123"
    );
    //Establishes the connection
    $conn = sqlsrv_connect($serverName, $connectionOptions);
    if($conn){
        echo "Connected!";

    }else{
        echo "Failed";
    }

BUT, when I tried to migrate using php artisan migrate, it return QueryExeption

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

Exception trace:

1 PDOException::("could not find driver")

C:\wamp64\www\frontdesk.sys\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

2
PDO::__construct("dblib:host=DESKTOP-ATB1EFG:1433;dbname=frontdesk;charset=utf8", "sa", "something_secret123", []) C:\wamp64\www\frontdesk.sys\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

I have checked with php 7.2.10, it already enables extensions

extension=php_sqlsrv_72_nts_x64.dll
extension=php_pdo_sqlsrv_72_nts_x64.dll
extension=php_sqlsrv_72_ts_x64.dll
extension=php_pdo_sqlsrv_72_ts_x64.dll

php.ini extensions

4
You should not be using ts (thread-safe) and nts (non thread-safe) versions of the sqlsrv extensions at the same time. Also, did you make sure that the extensions are enabled in both the php.ini for the CLI as well as the webserver (php-fpm or whatever)?Namoshek
Thanks for your comment, now it is working. I need to add to both php.ini in php folder and php.ini in apache folder. thanks.Lim Socheat

4 Answers

3
votes

I fixed the problem by adding extensions:

extension=php_pdo_sqlsrv_71_ts_x64.dll
extension=php_sqlsrv_71_ts_x64.dll

to both php.ini in php7.1.22 folder and php.ini in apache folder.

Thanks.

0
votes

Sometimes it doesn't work to run migrations with Git Bash in Xampp. In my case, use the Laragon terminal or you can try the Windows terminal.

0
votes

This link helped me with proper installation:

https://www.danhendricks.com/2017/11/installing-microsoft-sql-server-php-extensions-plesk-onyx/

I didn't even need to make 3. step. You need to install Microsoft ODBC Driver for SQL Server and Microsoft Drivers for PHP for SQL Server.

And then you can check connection through Tinker. Just be sure you use the sam PHP version for both environments.

php artisan tinker
DB::connection('your_sqlsrv_connection_name')->getPdo();
-3
votes

Currently laravel supports

MySQL
PostgreSQL
SQLite
SQL Server

If you are using any of these just follow the tip

Open your .env file and you will find the bunch of variables

and in that you will find these

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

EG: just change DB_CONNECTION to you current database such as SQLite

and fill you credentails and username ,databasename

See the supported Database here https://laravel.com/docs/5.7/database#introduction