Creating a database class in PHP with MySQLi
What is the purpose of this class?


  Creating a database class in PHP with mySQLI


MySQLi is a "database class."  (Whatever meaning of "database class" you choose)


Are you trying to make a class that adds on to MySQLi?
Are you trying to make a class that abstracts away certain operations (a DBAL)?
Are you trying to make a class that maps objects to a database (ORM)?


require_once("db_constants.inc.php");

The file that your class is defined in does not need to be aware of your connnection details.  Only the file that uses the class needs to know that, not the file that defines the class (unless of course, it's the same file, but it rarely should be).

or die

Constructors cannot return values, so this will never work.

The proper way to handle errors with objects is exceptions.  Please note though that exceptions should only be used when something that's actually exceptional happens.  It's far to easy to fall into the anti-pattern of using exceptions as return values.

In the case of mysqli's constructor failign to create a connection, that is definitely a cause for an exception.  (I tend to avoid the possibility of an object being in an unstable state.)

closeConnection

Why does this take a parameter when the connection is encapsulated in the class?

Also, unless you're going to have an openConnection method, avoid this.  Just let the destructor handle this.  Why would a user ever want to close the connection but keep the instance alive?

PDO vs MySQLi

I'm heavily biased in this one since I've always used PDO and never written a single line of code with MySQLi, but I've never seen the advantage of MySQLi over PDO.  I suppose there's a few MySQL functionalities that MySQLi supports and PDO doesn't, but they must be quite edge cases as I've never run into anything.

Concluding Remarks

I feel like there's barely anything here to review.  The goal of your code is not quite clear.  Can you explain a little more what your end goal is?  What is the purpose of this class?  What is an example use case?