0

Hello,

I am trying to connect to sql with pdo. I wonder why it does not work? And anyone has any clue how to fix the error?

Current php version : 5.6.8
Fatal error: Undefined class constant 'ERRORMODE_EXCEPTION' in C:\xampp\htdocs\latihan2\latihan4.php on line 16

latihan4.php

<?php

echo "Current php version : ".phpversion();

$servername = "localhost";
$username = "root";
$password = "";

try {
    $conn = new PDO("mysql:host=$servername;dbname=twotables", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRORMODE_EXCEPTION);
    echo "Connected successfully";
    }
catch(PDOException $e)
    {
    echo "Connection failed: ". $e->getMessage();
    }
?> 
2
Contributors
1
Reply
13
Views
2 Years
Discussion Span
Last Post by diafol
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.