問(wèn)題描述
在 SQLSRV 驅(qū)動(dòng)程序與 PDO 驅(qū)動(dòng)程序之間進(jìn)行選擇時(shí),我應(yīng)該考慮哪些因素(對(duì)于帶有 MS SQL 服務(wù)器的 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 時(shí),哪個(gè)更好(1)SQL Server 的本機(jī)驅(qū)動(dòng)程序或(2)PDO 驅(qū)動(dòng)程序? )但答案似乎有點(diǎn)缺乏并且沒(méi)有沒(méi)有提到 這篇文章.
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.
我正在尋找一個(gè)全面的和最新的(例如,SQLSRV 驅(qū)動(dòng)程序是否仍然只適用于 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 允許您編寫(xiě)合理的 DB 中立的代碼.
PDO allows you to write you code to be reasonably DB-neutral.
如果你想要真正的數(shù)據(jù)庫(kù)中立,你會(huì)想要使用一個(gè)完整的數(shù)據(jù)庫(kù)抽象層,比如 NotORM-- 使用普通 PDO,您仍然需要注意 SQL 語(yǔ)法差異,但至少您的基本 PHP 代碼將與 DB 無(wú)關(guān).
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 中立現(xiàn)在似乎并不重要——如果你使用 SQL Server,那么你可能被告知這是必需的,沒(méi)有別的——但是你無(wú)法預(yù)測(cè)事情會(huì)如何改變未來(lái),所以如果選擇是在 DB 中立驅(qū)動(dòng)程序和 DB 特定驅(qū)動(dòng)程序之間,并且您沒(méi)有任何其他理由偏愛(ài),那么選擇中性驅(qū)動(dòng)程序......它會(huì)讓生活變得很多如果您的公司被接管并且新老板想使用 Oracle 作為數(shù)據(jù)庫(kù),則更容易!
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!
此外,因?yàn)樗?DB 中立的,所以 PDO 在 PHP 社區(qū)中更標(biāo)準(zhǔn)且更廣為人知.與使用 MSSQL 驅(qū)動(dòng)程序相比,您將從在線站點(diǎn)(如本站點(diǎn))獲得更多有關(guān) 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.
這篇關(guān)于SQLSRV 驅(qū)動(dòng)程序與用于 PHP 和 MS SQL Server 的 PDO 驅(qū)動(dòng)程序的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!