开发者

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?

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 wi开发者_如何学JAVAth FreeTDS, but I'd like to know if this isn't the best way.

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.

The response to this stackoverflow question seems to touch on what I'm asking, however it's Windows centric.

Thank you!


I've had good results using PHP's PDO (PHP Data Objects) library for this sort of thing. There's an excellent tutorial at 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. 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.

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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜