Ad Code

Ticker

6/recent/ticker-posts

Connect MySQL to PHP / Easyteachyt

Connect MySQL server to php for backed is important because we want a database .

So follow my step its is a short blog for this for full explanation watch video.

Copyright : It is property of codingwithharry

Some example of code To Connect MySQL to PHP

Example 1 : To Connect MySQL to PHP

Open a Connection to MySQL.
Before we can access data in the MySQL database, we need to be able to connect to the server:

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

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

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

Close the Connection
The connection will be closed automatically when the script ends. To close the connection before, use the following:

MySQLi Object-Oriented:
$conn->close();
MySQLi Procedural:
mysqli_close($conn);

PDO:
$conn = null;

Post a Comment

0 Comments