在 PHP 中设置 SQLite3 PDO 驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4608863/
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
Setting Up SQLite3 PDO Drivers in PHP
提问by wayneLN
I'm working my way 'slowly' through the php101 tutorials and have got to number 9, where I need SQLite.
我正在通过 php101 教程“慢慢地”工作,并且已经到了第 9 位,在那里我需要 SQLite。
I've got SQLite3 running and can access via the CLI, (see screenshot of a little test DB) but when I try the tutorial scripts in php101, I get a blank browser screen. I now know this is because SQLite3 uses PDO (php101 is based on SQLite v2).
我已经运行了 SQLite3 并且可以通过 CLI 访问(参见一个小测试数据库的屏幕截图)但是当我在 php101 中尝试教程脚本时,我得到了一个空白的浏览器屏幕。我现在知道这是因为 SQLite3 使用 PDO(php101 基于 SQLite v2)。
Couldn't post and image so CLI says:
无法发布和图像,所以 CLI 说:
SQLite version 3.7.2
SQLite 版本 3.7.2
Enter ".help" for instructions
输入“.help”获取说明
Enter SQL statements terminated with a ";"
输入以“;”结尾的 SQL 语句
sqlite> select * from books;
sqlite> 从书籍中选择 *;
1|The Lord of the Rings|J.R. Tolkien
1|指环王|JR托尔金
Etc Etc
等等等等
Rather than go backwards, I'm trying to figure out how to enable the SQLite3 PDO driver (which I know is named sqlite) but those who have posted on stackoverflow to date, seems to have the SQLite driver installed and enable already, so driver config was not actually explained.
我没有倒退,而是试图弄清楚如何启用 SQLite3 PDO 驱动程序(我知道它被命名为 sqlite),但那些迄今为止在 stackoverflow 上发布的人似乎已经安装并启用了 SQLite 驱动程序,所以驱动程序实际上没有解释配置。
(sorry could post an image) but phpinfo for PDO says:
(抱歉可以张贴图片)但 PDO 的 phpinfo 说:
PDO
PDO
PDO support | enabled
PDO 支持 | 启用
PDO drivers |mysql
PDO 驱动程序 |mysql
pdo_mysql
pdo_mysql
PDO Driver for MySQL |enabled
适用于 MySQL 的 PDO 驱动程序 |已启用
Client API version |5.1.49
客户端 API 版本 |5.1.49
I've checked on www.phpro.org/tutorials/Introduction-to-PHP-PDO but it is not explained there either.
我在 www.phpro.org/tutorials/Introduction-to-PHP-PDO 上查过,但那里也没有解释。
My System is Linux Ubuntu 10.10
我的系统是 Linux Ubuntu 10.10
Apache - version 2.2.16
Apache - 版本 2.2.16
PHP version 5.3.3
PHP 版本 5.3.3
SQLite 3.7.2
SQLite 3.7.2
I'm trying to get this running on localhost as a learning aid initally.
我试图让它在本地主机上运行,作为最初的学习辅助。
Can someone explain how to install/configure the SQLite3 driver.
有人可以解释如何安装/配置 SQLite3 驱动程序。
回答by wayneLN
It's all easy when you know how, eventually found a post on www.news.php.net which provided a clue.
当您知道如何操作时,一切都很容易,最终在 www.news.php.net 上找到了提供线索的帖子。
So for anyone else stuck on this, just open a terminal and enter:
因此,对于其他坚持此问题的人,只需打开一个终端并输入:
sudo apt-get install php5-sqlite
note don't put a 3 and the end just leave it as sqlite
注意不要放 3 并且最后只是将其保留为 sqlite
You will have to restart your machine, if you then check phpinfo you will find an entry for SQLite and the drivers enabled for sqlite2 and sqlite (note sqlite is the SQLite3 driver)
你将不得不重启你的机器,如果你然后检查 phpinfo,你会发现 SQLite 的条目以及为 sqlite2 和 sqlite 启用的驱动程序(注意 sqlite 是 SQLite3 驱动程序)
Hope this helps someone else in the future.
希望这可以帮助其他人在未来。
回答by Web Developer in Pune
For Ubuntu 14.04
对于 Ubuntu 14.04
sudo apt-get install php5-sqlite
sudo service apache2 restart
In ubuntu 16.04 there is no php5-sqlite
在 ubuntu 16.04 中没有 php5-sqlite
sudo apt-get install php7.0-sqlite
sudo service apache2 restart