Connect PHP Code with DataBase


Prev Tutorial Next Tutorial

Connect PHP Code with DataBase

mysqli_connect() function is used to connect php code with MySQL database. It returns resource if connection is established otherwise null.

Syntax

resource mysqli_connect (server, username, password)  

PHP mysqli_close()

mysqli_close() function is used to disconnect php code with MySQL database. It returns true if connection is closed otherwise false.

Syntax

bool mysqli_close(resource $resource_link)

Connect php code with MySQL Database

Example to connect php code with MySQL Database

<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn)
{
  die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";

mysqli_close($conn);  

?>

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements