mysqli,OOP与程序 [英] mysqli, OOP vs Procedural

查看:61
本文介绍了mysqli,OOP与程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次看到这个.我不知道您可以通过执行类似的操作来实例化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过程与oop有什么区别?有没有?我是否必须安装某种扩展程序,还是可以在代码中开始使用?这里是newb,所以不太确定.

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.

推荐答案

Internet上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.

包括我在内的开发人员通常比mysqli更喜欢PDO.首先,它不仅可以处理MySQL,还可以处理更多的数据库.

PDO is generally favoured over mysqli by developers, including me. For one, it can handle many more databases than just MySQL.

这篇关于mysqli,OOP与程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆