Home » Php » What is PDOEception? Is it a typo? PHP Database connection doesn't work with PDOException [on hold]

What is PDOEception? Is it a typo? PHP Database connection doesn't work with PDOException [on hold]

Posted by: admin June 30, 2018 Leave a comment

Questions:

I am following a tutorial on PHP and connecting it to a MySQL database.

The catch block takes a odd parameter PDOEception which I thought was a typo of PDOException.

The code executes as expected with PDOEception but not with PDOException.

I couldn’t find any documentation on PDOEception.

What is PDOEception and why didn’t it work with PDOException?

database.php

<?php
class Database{
    private $host='localhost';
    private $user='root';
    private $pass='pass';
    private $dbname='mydb';

    private $dbh;
    private $error;
    private $stmt;

    public function __construct(){

        //set DSN
        $dsn='mysql:host='.$this->host.';dbanme='.$this->dbname;

        //set options

        $options= array(
            PDO::ATTR_PERSISTENT=>true,
            PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION
        );

        //create new pdo
        try{
            $this->dbh=new PDO($dsn,$this->user,$this->pass,$options);
        echo "tried";
        }
        catch(PDOEception $e) {
            $this->error= $e->getMessage();


        }

    }
}

?>

index.php

<?php

require 'classes/database.php';

$database=new Database;

?>
Answers: