PHP 7 MySQL connect to database code with a demo.

PHP 7 MySQL connect to database code with a demo.

PHP 7 MySQL | connect to database code with a demo and code step by step using PHP 7 MySQL.
 
Step 1 : PHP function connect to database with params.
mysqli_connect

Step 2 : Understand the complete PHP 7 code script as below:

<?php
$host_name = "127.0.0.1";
$db_username = "db_username";
$db_password = "db_password";
$db_name = "your_db_name_here";

$link = mysqli_connect($host_name, $db_username, $db_password, $db_name);

if (!$link) {
  echo "Error: Unable to connect to MySQL." . PHP_EOL;
  echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
  echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
  exit;
} else {
  echo "Connection success";
  # Now excute your next MySQL queries etc.
}

mysqli_close($link);
?>

Any query? Please share your thoughts in the comments below. Glad to help you!Thanks!

Was this page helpful? Do not forget to share this post!

Leave a Reply

Your email address will not be published. Required fields are marked *