By using new mysqli, we create the new object $connection. We can then use all available methods on the object such as query() to run SQL commands on our database connection.

PHP MySQL

By using new mysqli, we create the new object $connection. We can then use all available methods on the object such as query() to run SQL commands on our database connection.

Create MySQL database

We must pass at least three parameters to mysqli - $host, $user and $password, so we can successfully connect to our database. Let's create the connection:

$host = 'localhost'; $user = 'root'; $password = 'pass123'; //$connect becomes object instance type of mysqli class $connect = new mysqli( $host, $user, $password ); //we can now run methods on our $connect object using the dart operator $connect->query("CREATE DATABASE pages");

If we then connect to mysql via the command prompt console, and type "show databases;", we should see something that looks similar to the following if everything went well:

mysql> show databases; +--------------------+ | Database | +--------------------+ | pages | +--------------------+ 1 rows in set (0.00 sec)