phpdatabasesqlite

Create new database in php with SQLite3


How to create a new database in PHP with SQLite3?

$db = new SQLite3($dbname);

just opens the db, but I want to create if not exist.


Solution

  • To create you do use the new statement:

    // create or open (if exists) the database
    $database = new SQLite3('myDatabase.sqlite');
    

    If you have named a database that doesn't exist it should get created.