There's no better way, in the end it's all the same.
Looking at the PHP manual:
link
You see that the mysqli_connect
function is synonymous with the __construct()
method (which is what happens when you use new
), so
$db = mysqli_connect('localhost', 'user', 'pass', 'demo');
is the very same thing that
$db = new mysqli('localhost', 'user', 'pass', 'demo');
Use what "match" more with your code style. As is PHP, which is nothing more than a "script processor" that does not maintain the internal state between calls, other than compiled languages where the modules or even the whole application runs in the same context, it is possible to mix the paradigms without any problem, without advantages and disadvantages, and so it becomes a matter of "aesthetics" and really you choose what suits your workflow.