0

I have a class with PDO connection that is extended by other class that has functions that get and add data from form, but when I try to add same id using this form it doesn't show any errors/adds it to data base

    <?php

class Dbh{
  private $host = "localhost";
  private $user = "root";
  private $pwd = "";
  private $dbName = "warehouse";

  protected function connect(){
    $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbName;
    try{
    $pdo = new PDO($dsn, $this->user, $this->pwd);
  }catch(PDOException $e){
    echo $e->PDO::errorInfo();
  }
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    return $pdo;
  }

}

?>

How can I get error message specifying that id isn't unique

mrplee
  • 1
  • 1
  • Does your table structure required ID to be unique? Maybe it's auto-increment? – Justinas Apr 22 '20 at 07:23
  • Don't you need to enable Exceptions mode in PDO if you want to use try/catch for error handling? In any case, we'd need to see the code for the actual write to the database to see why it's not trapping an error. – droopsnoot Apr 22 '20 at 09:48

0 Answers0