• 11

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Error: file is encrypted or is not a database

I used PHP to create a database with a table. I did it in the following way:

$db = new SQLiteDatabase("test.db");
$db = sqlite_open("test.db");
sqlite_query($db,"create table students (names char(255))");

After I execute my PHP file from the command line: "php test.php" I get a new file in my directory which is called "test.db" (this is what I wanted). Than, in the command line, I type "sqlite3 test.db". In this way I enter in the sqlite command line session. Then, withing sqlite3, I type ".tables" (I wanted to check if a new database contains tables which it is supposed to contain). As the result I get:

Error: file is encrypted or is not a database 

So, it does not work. Does anybody know something about this problem? Thank you in advance for any help.

This is a version mismatch issue.

To open a database using PHP5 and SQLite we need to use a PDO and not the sqlite_open() function. An example of how to open or create a database:

    /*** connect to SQLite database ***/

    $dbh = new PDO("sqlite:VPN0.sqlite");
    echo "Handle has been created ...... <br><br>";

catch(PDOException $e)
    echo $e->getMessage();
    echo "<br><br>Database -- NOT -- loaded successfully .. ";
    die( "<br><br>Query Closed !!! $error");

echo "Database loaded successfully ....";
  • 46
Reply Report

I faced the same problem, use pdo instead of sqlite_open()

this link is very helpful and here is my code snippet, works perfectly, hope it helps

$dir = 'sqlite:YourPath/DBName.db';
$dbh  = new PDO($dir) or die("cannot open the database");
$query =  "SELECT * from dummy_table";
foreach ($dbh->query($query) as $row)
    echo $row[0];
  • 14
Reply Report

I recently encountered this exact same problem and have figured out what is going on. (Yes all the other answers are correct - it is a version mismatch problem.) A am posting this to provide some additional information that may be helpful to others encountering this problem...


The error is due to the fact that the sqlite3.exe command line tool (which implements SQLite version 3), cannot read database files created using PHP's procedural interface to SQLite (which implements SQlite version 2).


I am following a tutorial which describes how to use SQLITE with PHP: SQLite PHP tutorial (Note that I am running PHP 5.2.14 on Windows XP). As it turns out PHP 5.2 has two (incompatible) ways of interfacing with the SQLite database management system; a procedural API (SQLite) and an object oriented API (SQLite Functions (PDO_SQLITE)). The procedural API uses SQLite version 2 and the OOP API uses SQLite version 3. For Windows PHP platforms, the procedural API is enabled by uncommenting this line in php.ini:


While the OOP API is enabled by uncommenting these lines:


Note that there is a free Win32 tool that allows administration and manipulation of any version of SQLite databases: SQLite Administrator. This tool allows one to convert a version 2 database (created with the procedural API of PHP) into a version 3 database that can be read using the sqlite3.exe command line tool.

  • 3
Reply Report

Why do you open the db two times ?

Try this code:

$db = sqlite_open( "test.db", 066, $err );
sqlite_query( $db, "CREATE TABLE students (names VARCHAR(80))" );
sqlite_close( $db );

Edit: Fin is probably right; maybe you have to check the SQLite version with phpinfo().

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions