Answers for "how to make a database connection in php"

PHP
16

how to connect to a database in php

<?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";
?>
Posted by: Guest on November-10-2019
1

database connection in php

<?php

$hostName = 'localhost';
$userNmame = 'root';
$password = '';
$dbname = 'topproduct';
$db_name = "mysql:host=$hostName;dbname=$dbname";
$conn = new PDO($db_name,$userNmame,$password);

if(!$conn){
    echo 'Error database connection';    
}
Posted by: Guest on June-01-2021

Code answers related to "how to make a database connection in php"

Browse Popular Code Answers by Language