如何在 Apache 2.4 (Windows 7) 上为 PHP 5.6.14 配置 SQLite3?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33940419/
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 to configure SQLite3 for PHP 5.6.14 on Apache 2.4 (Windows 7)?
提问by Cesare
I'm on Windows 7, using PHP Version 5.6.14 on Apache 2.4 and I'm trying to access to a SQLite3 database.
我在 Windows 7 上,在 Apache 2.4 上使用 PHP 版本 5.6.14,我正在尝试访问 SQLite3 数据库。
I'm obtaining ....
我正在获取....
Fatal error: Class 'SQLite3' not found
致命错误:找不到“SQLite3”类
Here you're a simple php code ...
这是一个简单的php代码......
<?php
$db = new SQLite3('phpdb');
if ($db) {
$db->query("CREATE TABLE dogbreeds (Name VARCHAR(255), MaxAge INT);");
$db->query("INSERT INTO dogbreeds VALUES ('Doberman', 15)");
$result = $db->query("SELECT Name FROM dogbreeds");
var_dump($result->fetchArray(SQLITE3_ASSOC));
} else {
print "Connection to database failed!\n";
}
?>
I've just looking for information about and based on this at the moment I've this configuration in my php.ini file ...
我只是在寻找有关并基于此的信息,目前我的 php.ini 文件中有此配置...
extension=php_pdo_sqlite.dll
extension=php_sqlite3.dll
sqlite3.extension_dir = "D:\Cesare\Lavoro\Utili\Php-6-14\ext"
Any suggestions? Thank you very much in advance ....
有什么建议?非常感谢您提前......
Cesare
切萨雷
回答by Gary
Enable extension php by removing the ";" in front of ";extension=php_sqlite3.dll" in php.ini. Can you also manually check if the extensions are there in the path?
通过删除“;”启用扩展php 在 php.ini 中的“;extension=php_sqlite3.dll”前面。您还可以手动检查路径中是否存在扩展名吗?
`extension=php_pdo_sqlite.dll` AND `extension=php_sqlite3.dll`.
Try this
尝试这个
$db = sqlite_open("/absolute/path/my_sqlite.db");
or
或者
$db = new SQLiteDatabase('filename'))
回答by job wang
I met the same problem, I solved it by changing the "extension_dir" using the absolute path
我遇到了同样的问题,我通过使用绝对路径更改“extension_dir”来解决它
extension_dir = "C:/php/php7.0/ext"
the others setting
其他设置
extension=php_pdo_sqlite.dll
extension=php_sqlite3.dll
sqlite3.extension_dir = "C:/php/php7.0/ext"
回答by Renato Espinoza
I ran into the same problem: -I am doing the LinkedIn Learning for SQL Essentials.
我遇到了同样的问题:-我正在为 SQL Essentials 进行 LinkedIn 学习。
-My OS is windows server 2012 r2
-我的操作系统是 windows server 2012 r2
-I downloaded xampp from this website https://bw.org/ldcsql/, given by the instructor. I specifically downloaded the xampp version on this website even though there is a newer one(I uninstalled the newer one and installed the one from the website).
- 我从这个网站https://bw.org/ldcsql/下载了 xampp ,由讲师提供。我特地在这个网站上下载了 xampp 版本,即使有更新的版本(我卸载了较新的版本并从网站安装了一个)。
-Installed sqlite from https://www.sqlite.org/download.html(downloaded sqlite-dll-win64-x64-3240000.zip for my computer and the "sqlite-tools-win32-86-3240000.zip"). I unzipped them and copied the DLL and the def(from dll 64) to system32 folder and the "sqlite3" Application (from sqlite-tools) to system32 as well. A reference website just in case https://mislav.net/rails/install-sqlite3/
- 从https://www.sqlite.org/download.html安装 sqlite (为我的电脑下载了 sqlite-dll-win64-x64-3240000.zip 和“sqlite-tools-win32-86-3240000.zip”)。我解压缩它们并将 DLL 和 def(来自 dll 64)复制到 system32 文件夹,并将“sqlite3”应用程序(来自 sqlite-tools)复制到 system32。一个参考网站,以防万一https://mislav.net/rails/install-sqlite3/
Note: when I say "install" it means that I pasted the files to the system32, there is no wizard installation or anything else.
注意:当我说“安装”时,这意味着我将文件粘贴到 system32,没有安装向导或其他任何东西。
-In C:\xampp\php I looked for the php.ini which is of type "Configuration Settings", is NOT the php.ini-production NOR the php.ini-development. Inside there these should be uncommented: extension=pdo_mysql, extension=pdo_sqlite and extension=sqlite3.
- 在 C:\xampp\php 我查找了“配置设置”类型的 php.ini,不是 php.ini-production 也不是 php.ini-development。在里面这些应该是未注释的:extension=pdo_mysql、extension=pdo_sqlite 和 extension=sqlite3。
-Also in C:\xampp\php\ext check that you have php_pdo_mysql.dll, php_pdo_sqlite.dll and php_pdo_sqlite3.dll
-还在 C:\xampp\php\ext 中检查您是否有 php_pdo_mysql.dll、php_pdo_sqlite.dll 和 php_pdo_sqlite3.dll
And after all that it worked
毕竟它奏效了
回答by Wise_Guy
If you are using XAMPP click on "config" button select PHP(php.ini) then search "sqlite3" uncomment the ;extension=sqlite3 like this, extension=sqlite3 then find [sqlite3] and write the path where your php file and sqlite database reside like, [sqlite3] sqlite3.extension_dir ="D:\xampp\htdocs" then type localhost/yourphpfile.php in your browser you'll see the results of query.
如果您使用 XAMPP,请单击“配置”按钮选择 PHP(php.ini) 然后搜索“sqlite3”取消注释 ;extension=sqlite3 像这样,extension=sqlite3 然后找到 [sqlite3] 并写下您的 php 文件和 sqlite 的路径数据库位于 [sqlite3] sqlite3.extension_dir ="D:\xampp\htdocs" 然后在浏览器中输入 localhost/yourphpfile.php 你会看到查询的结果。