問題描述
我第一次看到這個.我不知道你可以通過做類似的事情來實例化一個 mysqli 類
I just saw this for the first time. I had no idea you can instantiate a mysqli class by doing something like
new mysqli( $host, $username, $password, $db );
這對我來說是全新的...連接到數據庫時,我在網上或書中看到的每個教程都是這樣的:
This is brand new to me...Every tutorial I have seen online or in books when connecting to database does something like this:
$conn = mysqli_connect( $host, $username, $password, $db );
if ( !$conn ) {
die( 'Sorry, could not connect');
}
為什么大多數教程都以程序方式進行操作?即使在我看到的有關創建單獨的數據庫類的教程中,也告訴我使用程序樣式代碼...
Is there a reason why most tutorials do it the procedural way? Even in tutorials I have seen on creating a separate database class, tell me to use the procedural style code...
mysqli procedural vs oop 有什么區別?有沒有?我是否必須安裝某種擴展,或者我可以開始在我的代碼中使用嗎?這里完全是新手,所以不太確定.
What's the difference with mysqli procedural vs oop? Is there any? Do I have to install any extensions of some kind or can I just start using in my code? Total newb here, so not really sure.
另外,什么時候使用 PDO 和 mysqli 比較好?處理大型企業應用程序的開發人員最常使用 PDO 嗎?或者只是喜好問題.
Also, when is it a good idea to use PDO vs mysqli? Is PDO used most commonly by developers that work on large scale Enterprise applications? Or is simply a matter of preference.
感謝您的幫助...
學習 php 很快就上癮了……我只是想知道的越來越多.
learning php has quickly become addictive...I just want to know more and more.
推薦答案
互聯網上 99% 的 PHP 教程已經過時,提倡糟糕的代碼,或者是由可能不應該教 PHP 的人編寫的(通常包括上述所有內容)).您應該找到一些好的.
99% of PHP tutorials on the internet are outdated, advocate terrible code or are written by people that probably shouldn't teach PHP (and commonly all of the above). You should find the handful of good ones.
PDO 通常比 mysqli 受到開發人員的青睞,包括我.一方面,它可以處理比 MySQL 更多的數據庫.
PDO is generally favoured over mysqli by developers, including me. For one, it can handle many more databases than just MySQL.
這篇關于mysqli、OOP 與程序化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!