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

Asked

Viewed 383 times

1

I’ve always used the mysqli the way I found most practical and never noticed any differences. Then came the question: why use the mysqli object-oriented? 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 it would be object-oriented:

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

Different of that question, I would not only like to know which is the best way. It is to know in detail what differs between the 2 methods.

  • 1

    Zero, the two are the same thing. The difference is that one is procedural style and the other is OO. https://secure.php.net/manual/en/mysqli.query.php

  • 1

    related https://answall.com/questions/33622/qual-%C3%A9-the-sure-to-connect-with-the-mysqli database

  • 1

    https://answall.com/questions/55493/quais-as-vantagens-pr%C3%A1ticas-de-utilizar-orienta%C3%A7%C3%A3o-a-objetos-no-dia-a-dia-de? Rq=1

1 answer

4


The OO or procedural API consumption changes very little. The advantage usually occurs 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 there’s no upside, there’s one if the IDE knows what to do. He may suggest the members he can use on an object of that type since the object is the focus. But the IDE would have to do a complex analysis or a kick because the language has dynamic typing and may have scripts injected, 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, that brings some advantage, I think bad use.

Besides, it is common for people not to use OOP in PHP correctly, which makes the situation worse. Actually this runs in other languages too, but in PHP it is terrible. Hence even advantages that could come from using OO ends up evaporating.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.