Answers for "connection with 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
0

connection php

<?php

function init_db()
{
    try {

        $host = 'localhost';
        $dbname = 'db_name';
        $charset =  'utf8';
        $user =   'root';
        $password =  '';

        $db = new PDO("mysql:host=$host;dbname=$dbname;charset=$charset",
            $user,
            $password);

    } catch (Exception $e) {
        die('Erreur : ' . $e->getMessage());
    }

    return $db;
}
Posted by: Guest on July-22-2021

Code answers related to "connection with php"

Browse Popular Code Answers by Language