Jump to content

Recommended Posts

I'm trying to learn PHP and sqlite from a tutorial which has the following code:

 

<?php
$sqlite = new SQLiteDatabase('music.db') or die ("Could not open database");

$sql = "SELECT artist_id, artist_name FROM artists";
if ($result = $sqlite->query($sql)) {
	if ($result->numRows() > 0) {
		while($row = $result->fetch()) {
		echo $row[0] . ":" . $row[1] . "\n";
			}
		} else {
	echo "No records matching your query were found.";
	}
} else {
	echo "ERROR: Could not execute $sql. " . sqlite_error_string($sqlite->lastError());
}

unset($sqlite);
?>

 

But I get this error:

Fatal error: Uncaught exception 'SQLiteException' with message 'SQLiteDatabase::__construct() [<a href='sqlitedatabase.--construct'>sqlitedatabase.--construct</a>]: file is encrypted or is not a database' in D:\xampp\htdocs\sqlite\music.php:3 Stack trace: #0 D:\xampp\htdocs\sqlite\music.php(3): SQLiteDatabase->__construct('music.db') #1 {main} thrown in D:\xampp\htdocs\sqlite\music.php on line 3

 

I'm not able to figure out where the error is. The database exists, but the contents can't be interpreted for some reason. When I query the DB from sqlite itself, I don't have any problem though. Could it be there's a version conflict? I'm using sqlite3, while the tutor is meant to be for sqlite2x.

 

I hope someone can hep me with this.

 

Thanks,

Bart

Link to comment
https://forums.phpfreaks.com/topic/179601-error-in-sqlite-script/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.