如何在Laravel中使用SQL Server连接? [英] How to use SQL Server connection in Laravel?

查看:647
本文介绍了如何在Laravel中使用SQL Server连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel 3中创建了一个工作项目,我必须切换到MsSQL Server(虽然不是我的电话,嗅探...),但我不理解此数据库类型上的Laravel配置...

I got a working project made in Laravel 3 that I have to switch to MsSQL Server (not my call though, sniff...) and I don't understand the Laravel configuration on this database type...

我将database.php内部的默认值更改为此'default' => 'sqlsrv',然后在sqlsrv数组中配置了主机,数据库,用户名,密码,但随后出现此错误消息:

I changed the default inside database.php to this 'default' => 'sqlsrv' then I configured the host, database, username, password in the sqlsrv array but then I get this error message:

此扩展程序需要Microsoft SQL Server 2012本机客户端ODBC驱动程序才能与SQL Server通信.

This extension requires the Microsoft SQL Server 2012 Native Client ODBC Driver to communicate with SQL Server`

经过一些研究,我发现我们需要SQLSRV的PDO,该版本在5.4版中已经存在,并且在我的phpinfo中,我得到了返回的pdo_sqlsrv support : enabled,因此,这似乎是正确的,但同时它似乎要求ODBC SQLSRV连接,我真的必须使用它吗?

After some research I found that we need PDO of SQLSRV, which I already have as version 5.4 and in my phpinfo I get this returned pdo_sqlsrv support : enabled so it seems all correct but at the same time it seems to ask for ODBC SQLSRV connections, does I really have to use that?

我宁愿直接从Laravel数据库连接进行连接...但是,即使我需要它并且创建了到服务器的ODBC连接,如何将它们放入配置中?这就是我的配置(当然my...会替换为我的真实详细信息):

I would rather connect directly from the Laravel database connection... but even if I need it and I created some ODBC connection to the server, how do I put them inside my configuration? Here is what I have in my configuration (of course the my... is replace by my real details) :

'sqlsrv' => array(
    'driver'   => 'sqlsrv',
    'host'     => 'myServerIP', 
    'database' => 'myDatabase',
    'username' => 'myUsername',
    'password' => 'myPassword',
    'prefix'   => '',
 ),

任何帮助将不胜感激,我发现唯一接近我问题的是Laravel论坛中的以下链接:在SQL Server上进行Laravel查询,但随后就停止而未进行任何配置.

Any help would be greatly appreciated, the only thing I found close to my problem was this link from the Laravel forum: Laravel query on SQL Server but then it just stop without giving any configurations.

推荐答案

经过大量研究,我发现SQL Server Native Client 10.0的驱动程序已过时并且不足以通过PDO连接到MsSQL Server 2008 ,您必须至少具有版本11.0才能连接到SQL Server 2005 +

Ahh after a lot more research, I found out that my driver of SQL Server Native Client 10.0 was out of date and not sufficient to connect to a MsSQL Server 2008 with PDO, you need to have at least version 11.0 in order to connect to an SQL Server 2005+

如果要验证驱动程序版本,可以浏览Control Panel >> Administrative Tools >> Data Sources (ODBC),然后单击Drivers选项卡以找出已安装的SQL Server Native Client.如果要更新驱动程序,请根据您的操作系统配置,在下面选择适当的链接...

If you want to validate your driver version, you can go through Control Panel >> Administrative Tools >> Data Sources (ODBC) and then click on the Drivers tab to find out which SQL Server Native Client you have already installed. If you want to update your driver, depending on your OS configuration you may choose the proper link below...

SQL Server 2012本机客户端
x86(32位)软件包 http://go.microsoft.com/fwlink/?LinkID=239647& clcid = 0x409
x64(64位)软件包 http://go.microsoft.com/fwlink/?LinkID=239648& clcid = 0x409

SQL Server 2012 Native Client
x86 (32 bits) Package http://go.microsoft.com/fwlink/?LinkID=239647&clcid=0x409
x64 (64 bits) Package http://go.microsoft.com/fwlink/?LinkID=239648&clcid=0x409

这篇关于如何在Laravel中使用SQL Server连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆