如何使用 PHP 和 Wamp Server 使用和访问 SQLite 数据库?
我知道 PHP 5 已经支持 SQLite,但由于某种原因我无法让它工作。
我按照 SQLite 教程:入门< 中的说明进行操作/a>. 我还确保以下内容没有从 php.ini 中注释掉:
extension=php_pdo_sqlite.dll
extension=php_sqlite.dll.
但是当我使用 Firefox 从本地主机打开 PHP 文件时,出现此错误:
致命错误:未找到“SQLiteDatabase”类。
顺便说一下,我使用的是 Windows,如果该信息很重要的话。
造成这个问题的原因可能是什么?
I know PHP 5 already supports SQLite but for some reason I can't get it to work.
I followed the instructions from SQLite tutorial: Getting started. I also made sure that the following are not commented out from 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:
Fatal error: Class 'SQLiteDatabase' not found.
I'm on Windows by the way, if that info matters.
What may be the cause of this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SQLiteDatabase
类是来自 sqlite 库的对象,该支持在 PHP 5.4 中被删除,但在各种系统和早期版本中可能会禁用配置,因为该库长期以来被标记为将被弃用。较新版本的 PHP 不再支持库
php_sqlite.dll
(Windows) 或php_sqlite.so
(Linux),并已替换为php_sqlite3.dll
> 或php_sqlite3.so
分别。您可以:
尝试在 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 和 SQLite3 PHP 手册页更改必要的对象和函数调用。如果选择二,请注意,这不应该是一项艰苦的工作,因为变化并没有那么大。 例如,到目前为止我所学到的:
SQLiteDatabase
->SQLite3
、SQLiteDatabase::unbufferedQuery
->SQLite3::query
、SQLiteResult::fetchAll(SQLITE_*)
->SQLite3Result::fetchArray(SQLITE3_*)
等。至于获取,在旧的 SQLite 我们有:
虽然,在新的 SQLite3 我们应该:
其他更改需要类似的工作量,因此这不应该是一个终生过程。
当然,我强烈建议任何人继续选择第二选项。 在大多数情况下,进步是两个可用选项中更好的一个。
Class
SQLiteDatabase
is an object from sqlite library, 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.Library
php_sqlite.dll
(Windows) orphp_sqlite.so
(Linux) is no longer supported in newer versions of PHP and was replaced withphp_sqlite3.dll
orphp_sqlite3.so
respectively.You can:
Try to find
php_sqlite.dll
(php_sqlite.so
) somewhere in the Internet. Links like this or this may 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 safe orNTS
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 Studio to convert your database file from 2.1 to 3.0 (size can be lowered by even a half) and then carefully compare SQLite and SQLite3 PHP manual pages to change necessary objects and functions call.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.As for fetching, in old SQLite we had:
While, in new SQLite3 we should:
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 second option. Progress is in most cases the better one of two available options.
我认为
SQLiteDatabase
类来自扩展sqlite
而不是pdo_sqlite
。 因此,您可以启用sqlite
扩展,或使用 PDO 代替:I think the class
SQLiteDatabase
is from the extensionsqlite
ratherpdo_sqlite
. So you could enable thesqlite
extension, or use PDO instead:在 Windows 上,您需要在 ini 中进行以下设置:
我建议您阅读此页面< /a> 在手册中。
On Windows you need to have the following set in your ini:
I recommend you read this page in the manual.