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();
    }
?> 
Member Avatar for diafol

Try PDO::ERRMODE_EXCEPTION

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.