The common features between the above two connection methods are:
MySQLi has the ability to be procedural instead of Object Oriented.This means all the connections with a function call instead of using objects. It has the ability to connect to MySQL,MariaDB and MaxDB.
Step-1 : Navigate to http://localhost/phpmyadmin
in the browser or Windows user can directly go to XAMPP control Panel and click on MySQL -> Admin which takes to phpmyadmin homepage which looks like below.
Step-2 : Then go to User Accounts -> Add account -> Enter username, password, hostname -> Click in check box Check All -> Go as shown in below image.
Step-3 : Then create a new Database by clicking New -> enter Database Name -> Select Collation -> Create like shown below.
Step-4 : Then start creating a table in the database by giving the table name Authors -> No.of columns:4 -> Go
Step-5 : The final structure of the table looks like below with the various values in the table.
// Before going to do this, create a database and get HostName from phpmyadmin panel.
[php]
<!DOCTYPE html>
<html>
<body>
<?php
$dbPassword = "PHPFundamentals";
$dbUserName = "PHPFundamentals";
$dbServer = "localhost";
$dbName = "PHPFundamentals";
$connection = new mysqli($dbServer, $dbUserName, $dbPassword, $dbName);
print_r($connection);
if($connection->connect_errno)
{
echo "Database Connection Failed: ".$connection->connect_errno);
}
?>
</body>
</html>
[/php]
MySQLi Procedural
[php]
<!DOCTYPE html>
<html>
<body>
<?php
$dbPassword = "PHPFundamentals";
$dbUserName = "PHPFundamentals";
$dbServer = "localhost";
$dbName = "PHPFundamentals";
$connection = mysqli_connect($dbServer, $dbUserName, $dbPassword, $dbName);
print_r($connection);
if($connection)
{
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
</body>
</html>
[/php]
MySQLi (object-oriented)
[php]$connection->close();[/php]
MySQLi Procedural
[php]mysqli_close($connection);[/php]