Laravel 5.4 odbc连接MS SQL SERVER

时间:2023-01-19 15:52:47

I need to config Laravel 5.4 to use the ODBC PDO Driver for Microsoft SQL Server.I didnt find any useful resource. If anyone previously used odbc in laravel 5.4 please help me out.

我需要配置Laravel 5.4以使用Microsoft SQL Server的ODBC PDO驱动程序。我没有找到任何有用的资源。如果有人以前在laravel 5.4中使用过odbc,请帮帮我。

Database.php

    'odbc'   => [
        'driver'   => 'odbc',
        'dsn'      => 'Driver={SQL Server};Server=
        {serverName};Trusted_Connection=true;Database=meteor;',
        'host'     => 'DESKTOP-B9M4O7M\SQLEXPRESS',
        'database' => 'meteor',
        'username' => 'DESKTOP-B9M4O7M\admin',
        'password' => '',
        'grammar' => [
            'query' => Illuminate\Database\Query\Grammars\SqlServerGrammar::class,
            'schema' => Illuminate\Database\Schema\Grammars\SqlServerGrammar::class,
        ],
     ],

1 个解决方案

#1


0  

You have missed a couple of settings, and misunderstood a couple of others. Try the following:

你错过了几个设置,误解了其他几个。请尝试以下方法:

'odbc'   => [
    /* USE sql server as the driver, and set odbc settings (see below) */
    'driver'   => 'sqlsrv',

    /* Tell laravel that you are using odbc */
    'odbc'     => true,

    /* Set the ODBC data source, your previous dns */
    'odbc_datasource_name' => '{SQL Server}',

    /* There is no dsn config variable that I am aware of */
    /*'dsn'    => 'Driver={SQL Server};Server={serverName};Trusted_Connection=true;Database=meteor;', */

    /* host is the server */
    'host'     => '{serverName}', /*'DESKTOP-B9M4O7M\SQLEXPRESS',*/

    'database' => 'meteor',
    'username' => 'DESKTOP-B9M4O7M\admin',
    'password' => '',
    'grammar' => [
        'query' => Illuminate\Database\Query\Grammars\SqlServerGrammar::class,
        'schema' => Illuminate\Database\Schema\Grammars\SqlServerGrammar::class,
    ],
 ],

#1


0  

You have missed a couple of settings, and misunderstood a couple of others. Try the following:

你错过了几个设置,误解了其他几个。请尝试以下方法:

'odbc'   => [
    /* USE sql server as the driver, and set odbc settings (see below) */
    'driver'   => 'sqlsrv',

    /* Tell laravel that you are using odbc */
    'odbc'     => true,

    /* Set the ODBC data source, your previous dns */
    'odbc_datasource_name' => '{SQL Server}',

    /* There is no dsn config variable that I am aware of */
    /*'dsn'    => 'Driver={SQL Server};Server={serverName};Trusted_Connection=true;Database=meteor;', */

    /* host is the server */
    'host'     => '{serverName}', /*'DESKTOP-B9M4O7M\SQLEXPRESS',*/

    'database' => 'meteor',
    'username' => 'DESKTOP-B9M4O7M\admin',
    'password' => '',
    'grammar' => [
        'query' => Illuminate\Database\Query\Grammars\SqlServerGrammar::class,
        'schema' => Illuminate\Database\Schema\Grammars\SqlServerGrammar::class,
    ],
 ],