简体   繁体   English

Mac localhost上的Laravel 4:无法找到SQLSRV的驱动程序

[英]Laravel 4 on Mac localhost: Cannot find driver for SQLSRV

I'm trying to connect with Laravel 4 to an SQL Server database. 我正在尝试将Laravel 4连接到SQL Server数据库。 I'm getting an error, but I think it's a PHP error, not a Laravel error. 我收到错误,但我认为这是一个PHP错误,而不是Laravel错误。 It says PDOException: could not find driver . 它说PDOException: could not find driver I have the driver set to sqlsrv like another example in the database.php file. 我将驱动程序设置为sqlsrv就像database.php文件中的另一个示例一样。 Like I said, I think this is a PHP error, not Laravel. 就像我说的,我认为这是一个PHP错误,而不是Laravel。

I'm on localhost on my Mac. 我在Mac上的本地主机上。 Do I need to configure something in my php.ini file? 我需要在php.ini文件中配置一些东西吗? I found another article that said I need to comment out a MySQL driver under PDO. 我发现另一篇文章说我需要在PDO下注释掉一个MySQL驱动程序。 I also couldn't find that line in my php.ini . 我也在php.ini找不到该行。 But I need to connect to a MySQL database as well, anyway. 但无论如何我也需要连接到MySQL数据库。 What do I need to change in my php.ini file? 我需要在php.ini文件中更改什么?

I found this line: 我找到了这一行:

pdo_mysql.cache_size = 2000

But commenting it out did nothing even after restarting Apache. 但是在重新启动Apache之后,评论它什么都没做。

The sqlsrv driver is a windows-only driver according to the PHP Manual (www.php.net/manual/en/sqlsrv.requirements.php). 根据PHP手册(www.php.net/manual/en/sqlsrv.requirements.php),sqlsrv驱动程序是一个仅限Windows的驱动程序。 So you can't use that driver on Mac, Linux, Unix or any other operating system than the ones listed on that page. 因此,您无法在Mac,Linux,Unix或该页面上列出的操作系统之外使用该驱动程序。

I assume you are trying to connect to a remote SQL Server somewhere? 我假设您正在尝试连接到某个远程SQL Server? If you're on Mac, then SQL Server wouldn't be running on your local machine, so I guess the first question is whether or not you have a SQL Server running somewhere. 如果您使用的是Mac,那么SQL Server将不会在您的本地计算机上运行,​​所以我想第一个问题是您是否在某个地方运行SQL Server。

Second, from the server that is running PHP, you would need to connect using either FreeTDS or ODBC with FreeTDS. 其次,从运行PHP的服务器,您需要使用FreeTDS或ODBC与FreeTDS进行连接。

Since Laravel 4 uses PDO, you'll need to install FreeTDS and ODBC. 由于Laravel 4使用PDO,因此您需要安装FreeTDS和ODBC。 Laravel 4 doesn't use the mssql PHP extension. Laravel 4不使用mssql PHP扩展。 It uses PDO, so mssql won't get you anywhere with Laravel 4. 它使用PDO,所以mssql不会让你在任何地方使用Laravel 4。

If you're serving PHP from your Mac, I would say there are generally 4 different ways you could go: 如果您从Mac上提供PHP服务,我会说通常有4种不同的方式:

  1. The Easy, but costly way: Go to (www.macupdate.com/app/mac/23152/openlink-odbc-driver-for-sybase) and download and install OpenLink ODBC driver. 简单但昂贵的方式:访问(www.macupdate.com/app/mac/23152/openlink-odbc-driver-for-sybase)并下载并安装OpenLink ODBC驱动程序。 This allows you to create new ODBC connections using the Sybase (MSSQL) driver on a XNIX machine. 这允许您使用XNIX计算机上的Sybase(MSSQL)驱动程序创建新的ODBC连接。 There's an installation walk-through here (wikis.openlinksw.com/dataspace/owiki/wiki/UdaWikiWeb/InstallSybaseExpressOSX). 这里有一个安装步骤(wikis.openlinksw.com/dataspace/owiki/wiki/UdaWikiWeb/InstallSybaseExpressOSX)。 It comes with a 15 day trial, after which you would have to purchase it. 它提供了15天的试用期,之后您将不得不购买它。 As of this writing, it appears to cost somewhere in the range of $30 - $50 depending on the license you choose. 在撰写本文时,根据您选择的许可证,它的价格似乎在30美元到50美元之间。

  2. The harder, but free way: Follow http://blog.benjaminwalters.net/?p=10 (slightly outdated) to re-compile FreeTDS support into PHP on Mac (assuming you're using MAMP) 更难但更自由的方式:关注http://blog.benjaminwalters.net/?p=10 (稍微过时)在Mac上将FreeTDS支持重新编译成PHP(假设您正在使用MAMP)

  3. The far better, but also far more work way: Find a Virtual Machine Host software like VMWare Fusion and install a Linux server like Ubuntu 12.4. 更好,但也更多的工作方式:找到像VMWare Fusion这样的虚拟机主机软件并安装像Ubuntu 12.4这样的Linux服务器。 Make sure you install apache2 and PHP during the install process and then follow the steps here to get FreeTDS working on your new server machine. 确保在安装过程中安装apache2和PHP,然后按照此处的步骤使FreeTDS在新的服务器计算机上运行。

  4. Run PHP from the Windows Server that is running SQL Server 从运行SQL Server的Windows Server运行PHP

Milage will vary with each solution, and there is a learning curve in any case. Milage将随着每个解决方案而变化,并且在任何情况下都存在学习曲线。 I've been a PHP developer for a long time, and it took me days to figure out how to get connected to SQL Server for the first time from Linux. 我很长一段时间以来一直是PHP开发人员,我花了几天时间才弄清楚如何从Linux首次连接到SQL Server。 Thankfully, there are quite a few walkthroughs out there now, and FreeTDS has come a long way since that time. 值得庆幸的是,现在有很多演练,FreeTDS从那时起已经走了很长一段路。

Hope that helps. 希望有所帮助。 :) :)

I actually have this running on my setup. 我实际上已经在我的设置上运行了。 My best advice is to get on the Homebrew bus. 我最好的建议是搭乘Homebrew巴士。

https://github.com/josegonzalez/homebrew-php is where you're going to want to look for installing PHP and related items. https://github.com/josegonzalez/homebrew-php是你想要寻找安装PHP和相关项目的地方。 I don't remember exactly what I did but it wasn't particularly difficult. 我不记得我做了什么,但并不是特别困难。

First you'll need FreeTDS. 首先,你需要FreeTDS。

brew install freetds

Then, add Jose's formulas to your homebrew (instructions on the github page). 然后,将Jose的公式添加到您的自制程序中(github页面上的说明)。 After that, 之后,

brew install php5x --with-mssql  

brew options php5x

if you need more extensions. 如果你需要更多扩展。

Based on Jon Watson's comment, 基于Jon Watson的评论,

I've tried step 2, and it doesn't work. 我已经尝试过第2步,但它不起作用。 check my issue here https://github.com/laravel/laravel/issues/2180 在这里查看我的问题https://github.com/laravel/laravel/issues/2180

Step 3 is broken link and I think it's the same with step 2. 第3步是断开的链接,我认为它与第2步相同。

I also tried linux ODBC driver for Laravel (there are 2, google it), both doesn't work too . 我也尝试过Laravel的Linux ODBC驱动程序(有2个,google), 两者都不起作用 Although my simple test php works in both DBLIB and ODBC (compiled using official microsoft odbc unix driver). 虽然我的简单测试php适用于DBLIB和ODBC(使用官方微软odbc unix驱动程序编译)。

Step 4 definitely works, BUT you must use IIS for best stability. 第4步肯定有效,但你必须使用IIS以获得最佳稳定性。

That leaves step 1. OR, 离开第1步。或者,

Ditch Laravel4 and use good ol' AdoDB http://adodb.sourceforge.net/ which I've been using since 2006 and still working superbly (although not modern like Laravel) configure it using tutorial in http://docs.moodle.org/20/en/Installing_MSSQL_for_PHP Ditch Laravel4并使用了很好的'AdoDB http://adodb.sourceforge.net/ ,我自2006年以来一直在使用它并且仍然工作得非常好(虽然不像Laravel那样现代)使用http: //docs.moodle中的教程配置它。组织/ 20 / EN / Installing_MSSQL_for_PHP

I wonder why they don't build sqlsrv driver for linux too.... 我想知道他们为什么不为linux构建sqlsrv驱动程序....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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