简体   繁体   中英

Unable to migrate database using sqlsrv (could not find driver) in laravel 5.4

I try to use migrate databse (MS SQL) in laravel 5.4 but I got error:

$ php artisan migrate  

In Connection.php line 647:

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

PS: But for query I can use it's as normal . I have problem only when migration.

Assuming You are on Windows

Install Microsoft PHP Drivers

Microsoft PHP Driver for SQL Server

There are drivers for Linux As well.

Extract the downloaded file anywhere. We just need the *.dll's.

FOR WINDOWS10 x 64

Copy dll's to your PHP\\ext Directory.

Ensure php_pdo_sqlsrv_72_ts_x64.dll & extension=php_sqlsrv_72_ts_x64.dll are copied.

Now, Edit your PHP.INI file.

Add the following extensions

extension=php_pdo_sqlsrv_72_ts_x64.dll, extension=php_sqlsrv_72_ts_x64.dll

in your PHP.INI file (For windows 10 only, use related dll's on other windows & linux systems)

Restart Apache2 Server (it's in bin - Alternatively, as service in windows)

./httpd -k restart

Install MS ODBC Drivers(MUST INSTALL THESE AS WELL)

ODBC Driver for SQL Server

-install them.

Open SQL SERVER CONFIGURATION MANAGER

SELECT

PROTOCOLS FOR SQLSERVER

SELECT

TCP/IP

Protocol

Enabled = Yes

IP Address

IPAll TCP PORT = 1433

Restart MS SQL SERVER

Right Click Database Engine (IP Address/MSSQLSERVER) Restart

Now You can migrate your models to MS Server

LARAVEL .ENV

DB_CONNECTION=sqlsrv

DB_HOST=localhost OR PCNAME\\MSSQLSERVERNAME

DB_PORT=1433

DB_DATABASE=yourdatabase

DB_USERNAME=yourusername

DB_PASSWORD=yourpassword


CHECK THE CONNECTION

if(DB::connection()->getDatabaseName())
{
    echo "<h3>connected successfully to database ".DB::connection()->getDatabaseName() . "</h3>";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM