What are the advantages and disadvantages of using object-oriented mysqli? [duplicate]

1

I've always used mysqli in the way I thought it was most convenient and never noticed any differences. Then came the question: why use object-oriented mysql? What are its advantages and disadvantages?

To make understanding easier, an example of what I'm saying:

$mysqli = mysqli_connect('127.0.0.1', 'usuario', 'senha', 'meusite');
$mysqli_query($mysqli, $comando);

And how would you look at objects:

$mysqli = new mysqli('127.0.0.1', 'usuario', 'senha', 'meusite');
$mysqli->query($comando);

Different this question, I would not want to just know what the best way. And yes to know in detail what differs between the 2 methods.

    
asked by anonymous 27.06.2017 / 02:58

1 answer

4

The consumption of API OO or procedural changes very little. The advantage is usually in development, which in the case of PHP does not help much because the OO version is just a shell on top of the procedural. And people confuse a lot in creating something OO and consuming OO.

Not to mention that there is no advantage, there is one if the IDE knows what to do. It can suggest the members that can use in object of that type since the object is the focus. But the IDE would have to do a complex analysis or make a kick because the language has dynamic typing and may have injected scripts, ie IDE does not do this because it can go very wrong, so the advantage is almost theoretical.

Anything that is used without a good justification, which brings some advantage, I find it bad to use.

Outside it is common for people not to use OOP in PHP correctly, which makes the situation worse. Actually this runs in other languages as well, but in PHP it's terrible. Hence the advantages that could come from the use of OO ends up evaporating.

There is even a disadvantage as it is an extra layer to run, but it is not something relevant in PHP.

    
27.06.2017 / 03:09