简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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