PDO problem duplicate key

<?php

try{
    $pdo->query("INSERT INTO blablabla");
}
catch (\PDOException $e) {
    echo $e;
    if ($e->errorInfo[1] == 1062) {
        //The INSERT query failed due to a key constraint violation.
    }
}

//For SQLITE check if table exist with this request => SELECT name FROM sqlite_master WHERE type='table' AND name='table_name';

catch (\PDOException $e) { // backslash indicate global namespace
    //echo $e;
}
?>

In memory database

Another feature of SQLite is the ability to create tables in memory. This can be amazingly helpful if you wish to create tempory databases or tables or even for development code.

<?php
try {
    /*** connect to SQLite database ***/
    $db = new PDO("sqlite::memory");

    /*** a little message to say we did it ***/
    echo 'database created in memory';
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
//We see above that a database is created in memory and a message is displayed to let us know. If the creation of the database failed, a PDO exception would be thrown and the script terminated at that point, passing control to the catch block. 
?>

Source