沃梦达 / 编程问答 / php问题 / 正文

如何在 Laravel 中使用 SQL Server 连接?

How to use SQL Server connection in Laravel?(如何在 Laravel 中使用 SQL Server 连接?)

本文介绍了如何在 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 Native Client 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+

如果你想验证你的驱动版本,你可以通过控制面板>>管理工具>>数据源 (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

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

本文标题为:如何在 Laravel 中使用 SQL Server 连接?

基础教程推荐