database connectivity in php
snippet in php

php sql connection


$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn= mysqli_connect($servername,$username,$password,$dbname);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
echo "Connected Successfully.";

database connectivity in php


///////////neha jaiswal/////
/////set variable/////////
$db="cart_system";///database name
///create connection with db////
////check condition for connection fail or not
 if ($conn) {
 echo "connection success"; 
{echo "connection unsuccess"; 

db connection in php


Just include this Temlate in other file using PHP Include/Require Keywords
 And Make Connection In One Shot :)

    // echo "Welcome to Connecting of DB Tutorial!";
    // echo "<br>";

    // 1. PDO - Php Data Objects
    // 2. MySQLi extension

    // Set Connection Variable
    $server = "localhost";
    $username = "root";
    $password = "";
    $database = "test";

    // Create A Connection
    $con = mysqLi_connect($server, $username, $password, $database);

     // Check For Connection
        die ("Connection Terminated! by Die() function". mysqLi_connect_error());
    else {
        echo "Connection Succefully Happened! <br>";