Laravel 配置 ODBC 驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22660729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Config ODBC Driver
提问by Gabriel Matusevich
I need to config Laravel 4 to use the ODBC PDO Driver for SQL Server 2000
我需要配置 Laravel 4 以使用 SQL Server 2000 的 ODBC PDO 驱动程序
I have tested it in a plain PHP file and it works perfectly, However, I can't get the right config inside Laravel.
我已经在一个普通的 PHP 文件中对其进行了测试,它运行良好,但是,我无法在 Laravel 中获得正确的配置。
This is my connection string >
这是我的连接字符串 >
$conn = new PDO("odbc:Driver={SQL Server};Server=MyHOST;Database=myDb;User Id=sa;Password=;");
I got this so far in the Laravel config/database.php
到目前为止,我在 Laravel config/database.php 中得到了这个
Edit
编辑
Ok, i followed the instructions from https://github.com/ccovey/odbc-driverand i configured:
好的,我按照https://github.com/ccovey/odbc-driver的说明进行了配置:
I changed it to
我把它改成
'odbc' => array(
'driver' => 'odbc',
'dsn' => 'Driver={SQL Server};Server=MyServer',
'grammar' => 'SqlServerGrammar',
'username' => 'user',
'password' => 'pass',
'database' => 'staPPM',
),
Im getting an error FatalErrorException, Grammar not Found
我收到一个错误 FatalErrorException, Grammar not Found
回答by Antonio Carlos Ribeiro
Laravel 4 still does not support ODBC directly, you'll have to do it yourself or you can try to use this driver: https://github.com/ccovey/odbc-driver.
Laravel 4 仍然不直接支持 ODBC,你必须自己做或者你可以尝试使用这个驱动程序:https: //github.com/ccovey/odbc-driver。
You'll have to add connection that should look something like:
您必须添加应如下所示的连接:
'odbc' => array(
'driver' => 'odbc',
'dsn' => 'Driver={iSeries Access ODBC Driver};System=my_system_name;',
'grammar' => 'DB2',
'username' => 'foo',
'password' => 'bar',
'database' => '',
'grammar' => 'SqlServerGrammar',
),
As noted in the package docs, you have to provide a valid DSNto connect to your server: those ones are examples of valid connection strings:
如软件包文档中所述,您必须提供有效的 DSN才能连接到您的服务器:这些是有效连接字符串的示例:
"Driver={SQL Server};Server=(local);Trusted_Connection=Yes;Database=AdventureWorks;"
"Driver={Microsoft ODBC for Oracle};Server=ORACLE8i7;Persist Security Info=False;Trusted_Connection=Yes"
"Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\bin\Northwind.mdb"
"Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\bin\book1.xls"
"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\bin"
To know if your DSN is valid, you better test the DNS outside Laravel.
要知道您的 DSN 是否有效,您最好在 Laravel 之外测试 DNS。
If you have access to a Linux, you can test it by doing:
如果您可以访问 Linux,则可以通过执行以下操作来测试它:
apt-get install unixodbc
isql -v DSN_NAME db_username db_password
And it should answer with:
它应该回答:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
There's a bug in ccovey's source code and, for now, you should alter the source of ODBCDriverConnection
to:
ccovey 的源代码中有一个错误,现在,您应该将源代码更改ODBCDriverConnection
为:
/**
* Default grammar for specified Schema
* @return Schema\Grammars\Grammar
*/
protected function getDefaultSchemaGrammar()
{
return $this->withTablePrefix(new \Illuminate\Database\Schema\SqlServerGrammar);
}
I'll open an issue in the package Github so they get this fixed.
我将在 Github 包中打开一个问题,以便他们解决这个问题。