Home » Php » sql – PHP SQLITE3 Uncaught Exception: Unable to open database: bad parameter or other API misuse

sql – PHP SQLITE3 Uncaught Exception: Unable to open database: bad parameter or other API misuse

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m quite new to PHP and want to open/create a new sqlite database. The example I try to implement is from the php.net website: https://www.php.net/manual/en/sqlite3.open.php

<?php
class MyDB extends SQLite3
{
    function __construct()
    {

        $this->open('test.db');
    }
}
//phpinfo();
$db = new MyDB();

$db->exec('CREATE TABLE foo (bar STRING)');
$db->exec("INSERT INTO foo (bar) VALUES ('This is a test')");

$result = $db->query('SELECT bar FROM foo');
var_dump($result->fetchArray());
?>

The error I receive:

Fatal error: Uncaught Exception: Unable to open database: bad parameter or other API misuse in /var/www/html/index2.php:8 Stack trace: #0 /var/www/html/index2.php(8): SQLite3->open() #1 /var/www/html/index2.php(12): MyDB->__construct() #2 {main} thrown in /var/www/html/index2.php on line 8

Line 8 –> $this->open('test.db');

All the files in my /var/www/html folder have 777 rights (the folder itself too).
All the suggested fixes in google don’t work so far: I’ve changed all the file owners to apache besides giving 777 rights. Also I’ve tried to add different parameters to the call like SQLITE3_OPEN_CREATE.

Does anyone have another idea?

How to&Answers: