Saturday , November 23 2024

How can create connection with database usin php ?

First of all we need a connection with database. after this we can modify and access the data from the database.

Example:

<?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”;
?>

servername: “localhost”(always same)
username: username of the database
password: password of the database

new mysqli($servername, $username, $password) is used to create a connection with database.
tha value of $conn will we true or false. If connection created successfully value will be true and if any problem in connection value will be false.

now we can check our connection using $conn->connect_error .

About admin

Check Also

Convert Text To Image

You can convert text to image by using this php code. You then download the image …

Leave a Reply