I have some trouble to open a sqlite file
In the command line I get this:
#sqlite3 sms.db
SQLite version 3.6.20
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from message;
Error: file is encrypted or is not a database
The error is not when I connect, it's when I run a query
Checking the file gets me this
# file sms.db
sms.db: SQLite 3.x database
So it should not be a version problem - like opening a sqlite2 file with sqlite3
In php I have this:
try
{
/*** connect to SQLite database ***/
$db = new PDO("sqlite:path/sms.db");
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");
}
$result = $db->query('SELECT * from message') or var_dump($db->errorInfo());
Gets me this (not at connect but when the query is executed)
array(3) { [0]=> string(5) "HY000" [1]=> int(26) [2]=> string(38) "file is encrypted or is not a database" }
I use a Sql manager extension for firefox and there I can open the file without any problems(and run any query without any encryption or password). This is really strange for me. I have searched about this for the last hours but I didn't find any solution. Any help would be appreciated.
I have just tested on windows and I can open the database. I think the problem is related to the sqlite drivers.
On windows I have SQLite Library 3.7.7.1 On my centos server I have SQLite Library 3.6.20
Now the question is how do I update the php sqlite extension. I can not update the entire php (it may cause errors )
Commands like yum install php-pdo, yum install php5-sqlite3, do not work
Sometimes I get this error when moving php-scripts from one hosting to another. Most often it is bug in the mode sqlite WAL:
PRAGMA journal_mode = WAL;
To solve this problem you need to disable this option in the database. The easiest way to do this by replacing the 2 bytes in the file database \\x02\\x02 to \\x01\\x01 to the address \\x12 (dec 18) In bash, you can use commands:
do printf '\x01\x01' | dd of=basename.db bs=1 seek=18 count=2 conv=notrunc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.