問題描述
在 SQLSRV 驅動程序與 PDO 驅動程序之間進行選擇時,我應該考慮哪些因素(對于帶有 MS SQL 服務器的 PHP)?
What considerations should I take into account when choosing between SQLSRV driver vs. PDO driver (for PHP with MS SQL server)?
我看到了之前的 Stackoverflow 帖子(在 Windows 上使用 PHP 時,哪個更好(1)SQL Server 的本機驅動程序或(2)PDO 驅動程序? )但答案似乎有點缺乏并且沒有沒有提到 這篇文章.
I saw this previous Stackoverflow post ( When using PHP on Windows, what is better (1) the native driver for SQL Server or (2) the PDO driver? ) but the answer seems a bit lacking and doesn't mention all the benefits of using the SQLSRV driver as mentioned in this article.
我正在尋找一個全面的和最新的(例如,SQLSRV 驅動程序是否仍然只適用于 Windows?)答案,程序員可以將其稱為資源.
I'm looking for a comprehensive and up-to-date (eg. is it still the case that SQLSRV driver is only available for Windows?) answer that programmers can refer to as a resource.
推薦答案
PDO 允許您編寫合理的 DB 中立的代碼.
PDO allows you to write you code to be reasonably DB-neutral.
如果你想要真正的數據庫中立,你會想要使用一個完整的數據庫抽象層,比如 NotORM-- 使用普通 PDO,您仍然需要注意 SQL 語法差異,但至少您的基本 PHP 代碼將與 DB 無關.
If you want truly DB-neutral, you'd want to use a full DB abstraction layer like NotORM -- with plain PDO, you'd still need to be careful about SQL syntax difference, but at least your basic PHP code would be DB-neutral.
DB 中立現在似乎并不重要——如果你使用 SQL Server,那么你可能被告知這是必需的,沒有別的——但是你無法預測事情會如何改變未來,所以如果選擇是在 DB 中立驅動程序和 DB 特定驅動程序之間,并且您沒有任何其他理由偏愛,那么選擇中性驅動程序......它會讓生活變得很多如果您的公司被接管并且新老板想使用 Oracle 作為數據庫,則更容易!
Being DB-neutral may not seem important now -- if you're using SQL Server, then you've probably been told that's what is required and nothing else -- but you can't predict how things will change in the future, so if the choice is between a DB-neutral driver and a DB-specific driver, and you don't have any other reason for a preference, then go with the neutral one.... it'll make life a lot easier if your company gets taken over and the new boss wants to use Oracle as the DB!
此外,因為它是 DB 中立的,所以 PDO 在 PHP 社區中更標準且更廣為人知.與使用 MSSQL 驅動程序相比,您將從在線站點(如本站點)獲得更多有關 PDO 的幫助.
Also, because it's DB neutral, PDO is more standard and more well-known in the PHP community. You'll get a lot more help with PDO from sites online (like this one) than with the MSSQL driver.
這篇關于SQLSRV 驅動程序與用于 PHP 和 MS SQL Server 的 PDO 驅動程序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!