windows 如何使用 PHP 和 Wamp Server 使用和访问 SQLite 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1091180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use and access an SQLite DB using PHP and Wamp Server?
提问by Jarvis
I know PHP 5 already supports SQLite but for some reason I can't get it to work.
我知道 PHP 5 已经支持 SQLite 但由于某种原因我无法让它工作。
I followed the instructions from SQLite tutorial: Getting started. I also made sure that the following are not commented out from php.ini:
我按照SQLite 教程中的说明进行操作:入门。我还确保以下内容没有从 php.ini 中注释掉:
extension=php_pdo_sqlite.dll
extension=php_sqlite.dll.
But when I open the PHP file from localhost using Firefox, I get this error:
但是,当我使用 Firefox 从本地主机打开 PHP 文件时,出现此错误:
Fatal error: Class 'SQLiteDatabase' not found.
致命错误:找不到“SQLiteDatabase”类。
I'm on Windows by the way, if that info matters.
顺便说一下,我在 Windows 上,如果这些信息很重要的话。
What may be the cause of this problem?
这个问题的原因可能是什么?
采纳答案by Tom Haigh
I think the class SQLiteDatabase
is from the extension sqlite
rather pdo_sqlite
. So you could enable the sqlite
extension, or use PDO instead:
我认为该类SQLiteDatabase
是从扩展sqlite
而不是pdo_sqlite
. 所以你可以启用sqlite
扩展,或者改用 PDO:
<?php
$conn = new PDO('sqlite:c:/mydb.sq3');
$conn->exec('some sql query');
回答by Kieran Hall
回答by trejder
Class SQLiteDatabase
is an object from sqlitelibrary, which support was dropped in PHP 5.4, but on various systems and configuration could be disabled in an earlier releases, as this library was long time marked as going to be deprecated.
ClassSQLiteDatabase
是sqlite库中的一个对象,它的支持在 PHP 5.4 中被删除,但在早期版本中可以在各种系统和配置中禁用,因为这个库很长时间被标记为将被弃用。
Library php_sqlite.dll
(Windows) or php_sqlite.so
(Linux) is no longer supported in newer versions of PHP and was replaced with php_sqlite3.dll
or php_sqlite3.so
respectively.
较新版本的 PHP 不再支持库php_sqlite.dll
(Windows) 或php_sqlite.so
(Linux),并分别替换为php_sqlite3.dll
或php_sqlite3.so
。
You can:
你可以:
Try to find
php_sqlite.dll
(php_sqlite.so
) somewhere in the Internet. Links like thisor thismay be helpful for you. However, you'll have to carefully match old SQLite library file to your PHP's platform (x64
orx86
), build engine (VC6
,VC9
orVC11
), version (5.x
) and type (TS
for thread safeorNTS
for non-thread safe). This might be a hard task.Leave
php_sqlite.dll
(SQLiteDatabase
) behind and ship toward newphp_sqlite3.dll
(SQLite3
object). You have to first use a tool like SQLite Studioto convert your database file from 2.1 to 3.0 (size can be lowered by even a half) and then carefully compare SQLiteand SQLite3PHP manual pages to change necessary objects and functions call.
尝试在 Internet 上的某个地方找到
php_sqlite.dll
(php_sqlite.so
)。像这样或这样的链接可能对您有所帮助。不过,你得老SQLite库文件,精心搭配,以你的PHP的平台(x64
或x86
),生成引擎(VC6
,VC9
或VC11
),版本(5.x
)和类型(TS
用于线程安全或NTS
用于非线程安全的)。这可能是一项艰巨的任务。留下
php_sqlite.dll
(SQLiteDatabase
) 并运送到新的php_sqlite3.dll
(SQLite3
对象)。您必须首先使用SQLite Studio 之类的工具将您的数据库文件从 2.1 转换为 3.0(大小甚至可以降低一半),然后仔细比较SQLite和SQLite3PHP 手册页以更改必要的对象和函数调用。
If option two, note that this shouldn't be a hard work, as changes aren't that big. For example, what I've learned so far:
如果选项二,请注意这不应该是一项艰巨的工作,因为变化不是那么大。例如,到目前为止我所学到的:
SQLiteDatabase
->SQLite3
,SQLiteDatabase::unbufferedQuery
->SQLite3::query
,SQLiteResult::fetchAll(SQLITE_*)
->SQLite3Result::fetchArray(SQLITE3_*)
etc.
SQLiteDatabase
->SQLite3
,SQLiteDatabase::unbufferedQuery
->SQLite3::query
,SQLiteResult::fetchAll(SQLITE_*)
->SQLite3Result::fetchArray(SQLITE3_*)
等
As for fetching, in old SQLitewe had:
至于获取,在旧的SQLite 中,我们有:
$rowsIMEI = $db->unbufferedQuery($imeiSQL)->fetchAll(SQLITE_ASSOC);
foreach($rowsIMEI as $r)
{
...
}
While, in new SQLite3we should:
而在新的SQLite3 中,我们应该:
$rowsIMEI = $db->query($imeiSQL);
while($r = $rowsIMEI->fetchArray(SQLITE3_ASSOC))
{
...
}
Other changes requires similar amount of work, so this shouldn't be a life-time process.
其他更改需要类似的工作量,因此这不应是一个终生的过程。
I, of course, strongly advice anyone to go forward and choose secondoption. Progress is in most cases the better one of two available options.
当然,我强烈建议任何人继续选择第二个选项。在大多数情况下,进步是两种可用选项中较好的一种。