33 Program to connect PHP with MySQL Database using PDO::__construct().

Program:

<?php

    $host = "localhost";

    $user = "root";

    $pass = "1234";

   

    try

    {

        $conn = new PDO("mysql:host=$host;dbname=employees",$user,$pass);

        $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);

        echo "Connected Successfully";

    }

    catch(PDOException $e)

    {

        echo "Connection Failed:".$e->getMessage();

    }

?>


Output:

Program to connect PHP with MySQL Database using PDO::__construct().

Previous
Next Post »