Miletone

Rp0 / Rp1.000.000

Sunday, September 29, 2019

PHP : Connect on DATABASE

<?php
    $host = "localhost";
$dbname = "id8452667_shop";
$username = "id8452667_root";
$password = "andimahyudin95";

try {
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
    try {
$host = "localhost";
$dbname = "id8452667_shop";
$username = "id8452667_root";
$password = "andimahyudin95";
    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

} catch (PDOException $e) {
    die("Could not connect to the database $dbname :" . $e->getMessage());
}
?>

No comments: