简体   繁体   English

错误:文件已加密或不是数据库

[英]Error: file is encrypted or is not a database

I used PHP to create a database with a table. 我使用PHP创建带有表的数据库。 I did it in the following way: 我是通过以下方式做到的:

<?php
$db = new SQLiteDatabase("test.db");
unset($db);
$db = sqlite_open("test.db");
sqlite_query($db,"create table students (names char(255))");
sqlite_close($db);
?>

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). 从命令行执行PHP文件后:“ php test.php”,我在目录中获得一个名为“ test.db”的新文件(这是我想要的)。 Than, in the command line, I type "sqlite3 test.db". 然后,在命令行中输入“ sqlite3 test.db”。 In this way I enter in the sqlite command line session. 这样,我输入了sqlite命令行会话。 Then, withing sqlite3, I type ".tables" (I wanted to check if a new database contains tables which it is supposed to contain). 然后,使用sqlite3,键入“ .tables”(我想检查新数据库是否包含应该包含的表)。 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. 要使用PHP5和SQLite打开数据库,我们需要使用PDO而不是 sqlite_open()函数。 An example of how to open or create a database: 有关如何打开或创建数据库的示例:

try 
{
    /*** 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 ....";

I faced the same problem, use pdo instead of sqlite_open() 我遇到了同样的问题,使用pdo代替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];
}

this is most likely an version mismatch between the php sqlite version and your standalone sqlite executable. 这很可能是php sqlite版本与您的独立sqlite可执行文件之间的版本不匹配。

see this: http://us3.php.net/manual/en/book.sqlite.php - under "user contributed notes", from Andrew Paul Dickey. 请参见: http : //us3.php.net/manual/en/book.sqlite.php-在“用户贡献的笔记”下,作者是Andrew Paul Dickey。

for a quick solution you can install and use the sqlite2 standalone executable. 要获得快速解决方案,可以安装和使用sqlite2独立可执行文件。

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... (是的,所有其他答案都是正确的-这是版本不匹配的问题。)A发布此消息以提供一些其他信息,这些信息可能会对遇到此问题的其他人有所帮助...

Summary: 摘要:

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). 该错误是由于以下事实导致的: sqlite3.exe命令行工具(实现SQLite版本3)无法读取使用PHP的SQLite程序接口(实现SQlite版本2)创建的数据库文件。

Discussion: 讨论:

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). 我正在关注一个教程,该教程描述了如何在PHP中使用SQLITE: SQLite PHP教程 (请注意,我在Windows XP上运行PHP 5.2.14)。 As it turns out PHP 5.2 has two (incompatible) ways of interfacing with the SQLite database management system; 事实证明,PHP 5.2具有两种(不兼容)与SQLite数据库管理系统进行交互的方式。 a procedural API ( SQLite ) and an object oriented API ( SQLite Functions (PDO_SQLITE) ). 一个过程API( SQLite )和一个面向对象的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 : 程序API使用SQLite版本2,OOP API使用SQLite版本3。对于Windows PHP平台,通过在php.ini取消注释此行来启用程序API:

extension=php_sqlite.dll

While the OOP API is enabled by uncommenting these lines: 通过取消注释以下行来启用OOP API:

extension=php_pdo.dll
extension=php_pdo_sqlite.dll

Note that there is a free Win32 tool that allows administration and manipulation of any version of SQLite databases: SQLite Administrator . 请注意,有一个免费的Win32工具,可以管理和操作任何版本的SQLite数据库: 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. 此工具允许将第2版数据库(使用PHP的过程API创建)转换为第3版数据库,可以使用sqlite3.exe命令行工具读取该数据库。

The question is two years old but now it can be solved this way: 这个问题已经有两年了,但现在可以通过以下方式解决:

class MyDB extends SQLite3
{
    function __construct()
    {
            $dbFile = __DIR__ . '/../../../adminer/Dictionary.sqlite';
            $this->open($dbFile);
    }
}

$db = new MyDB();
$db->exec('CREATE TABLE students (names VARCHAR(80))');
echo "done";

Source: http://php.net/manual/en/sqlite3.open.php 来源: http : //php.net/manual/en/sqlite3.open.php

There's one more simple way to solve that problem. 有一种更简单的方法可以解决该问题。 You can convert sqlite 2 database file to sqlite 3. I did that with SQLiteManager program on Mac OS X. 您可以将sqlite 2数据库文件转换为sqlite3。我是在Mac OS X上使用SQLiteManager程序完成的。

Why do you open the db two times ? 为什么要两次打开数据库?

Try this code: 试试这个代码:

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

Edit: Fin is probably right; 编辑:Fin可能是正确的; maybe you have to check the SQLite version with phpinfo(). 也许您必须使用phpinfo()检查SQLite版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM