简体   繁体   English

在Linux上使用PHP 5.3+访问MS SQL的首选方法

[英]Preferred method of accessing MS SQL with PHP 5.3+ on Linux

What is the preferred method of accessing a Microsoft SQL Server database with PHP 5.3+ on Linux? 在Linux上使用PHP 5.3+访问Microsoft SQL Server数据库的首选方法是什么?

Given the different extension options now available I'm unsure which method is preferred based on reliability and performance. 鉴于现在可用的扩展选项不同,我不确定哪种方法是基于可靠性和性能的首选方法。 Right now I am using the mssql extension with FreeTDS, but I'd like to know if this isn't the best way. 现在我正在使用带有FreeTDS的mssql扩展,但我想知道这不是最好的方法。

I've heard some recommend using php-odbc/EasySoft because the mssql extension has been abandoned - yet others have said going the ODBC route isn't worth the performance hit. 我听说有人推荐使用php-odbc / EasySoft,因为mssql扩展已经被放弃了 - 但是其他人已经说过,ODBC路由不值得性能打击。

The response to this stackoverflow question seems to touch on what I'm asking, however it's Windows centric. 对这个stackoverflow 问题的回应似乎触及了我的要求,但它以Windows为中心。

Thank you! 谢谢!

I've had good results using PHP's PDO (PHP Data Objects) library for this sort of thing. 对于这种事情,我使用PHP的PDO(PHP数据对象)库获得了很好的结果。 There's an excellent tutorial at http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ . http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/上有一个很好的教程。 Just make sure you use the following template to initialize your database connection: 只需确保使用以下模板初始化数据库连接:

$dbh = new PDO("dblib:host=$host;dbname=$dbname", $user, $pass);

I use FreeTDS. 我使用FreeTDS。 It's far from satisfactory. 这远非令人满意。 In fact, I found your question because I live in hope that there must be a better solution and I keep looking for one. 事实上,我发现了你的问题,因为我希望必须有一个更好的解决方案,我一直在寻找一个。 Unfortunately, FreeTDS seems to be the best option at the moment, if you're developing in a Linux environment. 不幸的是,如果您正在Linux环境中开发,FreeTDS似乎是目前最好的选择。

If you were on Windows, you could obviously use the Microsoft SQL Server drivers for PHP which would be better, but even then there are missing features, like support for PDO lastInsertId() . 如果你在Windows上,你显然可以使用PHP的Microsoft SQL Server驱动程序,这会更好,但即便如此,也有缺少的功能,例如支持PDO lastInsertId()

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

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