Answers for "database connectivity in php"

PHP
18

php sql connection

<?php
$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.";
?>
Posted by: Guest on May-11-2020
1

database connectivity in php

<?php
///////////neha jaiswal/////
/////set variable/////////
$serve="localhost";
$user="root";
$password="";
$db="cart_system";///database name
///create connection with db////
$conn=mysqli_connect($serve,$user,$password,$db);
////check condition for connection fail or not
 if ($conn) {
 echo "connection success"; 
 }else
{echo "connection unsuccess"; 
 }
  ?>
Posted by: Guest on January-16-2021
3

db connection in php

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

<?php
  
    // 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
     if(!$con){
        die ("Connection Terminated! by Die() function". mysqLi_connect_error());
       
    }
    else {
        echo "Connection Succefully Happened! <br>";
    }


    ?>
Posted by: Guest on July-25-2020
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 "database connectivity in php"

Browse Popular Code Answers by Language