美文网首页
在centOS上使用php5+sqlite3遇到了问题的部分记录

在centOS上使用php5+sqlite3遇到了问题的部分记录

作者: 苍蝇的梦 | 来源:发表于2022-10-21 14:41 被阅读0次

2020-09-04 遇到的一点小问题

最近需要在一台centOS的机器上,使用php5和sqlite3,做一点小功能。

apt-get install php5-sqlite
重启  php5-cgi
Sublime联想出来的命令

安装后使用遇到了问题:

PHP Fatal error:  Call to undefined function sqlite_open() in /test.php on line 4

网上搜索了下,一堆没用的信息,都是修改php.ini文件。
跟着折腾半天才发现,这些都是sqlite,不是sqlite3。
使用命令php -m看了下,我只开启了sqlite3模块。修改下使用的代码。

//连接
$db = new SQLite3('/usr/share/nginx/html/files/wannoo');
//创建表
$db->exec('
  CREATE table country (tStart INTEGER,tEnd INTEGER);
');

记录下参考到的几个网页:
SQLite从Excel文件中导入数据

sqlite3文档

sqlite3执行完退出

因为文件权限不足,遇到了几个问题,顺便记录一下:
文件夹没有 x 执行权限

wannoo@wannoo:~$ php /home/wannoo/html/files/saos/test.json
PHP Fatal error:  Uncaught exception 'Exception' with message 'Unable to open database: unable to open database file' in /usr/share/nginx/html/files/saos/ip2country.php:29
Stack trace:
#0 /usr/share/nginx/html/files/saos/ip2country.php(29): SQLite3->__construct('/usr/share/ngin...')
#1 /usr/share/nginx/html/files/saos/ip2country.php(55): ip_country()
#2 /usr/share/nginx/html/files/saos/test.json(4): ip_cn()
#3 {main}
  thrown in /usr/share/nginx/html/files/saos/ip2country.php on line 29

Fatal error: Uncaught exception 'Exception' with message 'Unable to open database: unable to open database file' in /usr/share/nginx/html/files/saos/ip2country.php:29
Stack trace:
#0 /usr/share/nginx/html/files/saos/ip2country.php(29): SQLite3->__construct('/usr/share/ngin...')
#1 /usr/share/nginx/html/files/saos/ip2country.php(55): ip_country()
#2 /usr/share/nginx/html/files/saos/test.json(4): ip_cn()
#3 {main}
  thrown in /usr/share/nginx/html/files/saos/ip2country.php on line 29

文件夹没有w写入权限

wannoo@wannoo:~$ php /home/wannoo/html/files/saos/test.json
PHP Warning:  SQLite3::exec(): unable to open database file in /usr/share/nginx/html/files/saos/ip2country.php on line 47

Warning: SQLite3::exec(): unable to open database file in /usr/share/nginx/html/files/saos/ip2country.php on line 47

数据库文件没有w写入权限

wannoo@wannoo:~$ php /home/wannoo/html/files/saos/test.json
PHP Warning:  SQLite3::exec(): attempt to write a readonly database in /usr/share/nginx/html/files/saos/ip2country.php on line 44

Warning: SQLite3::exec(): attempt to write a readonly database in /usr/share/nginx/html/files/saos/ip2country.php on line 44

提一下权限解决问题。mkdir -m 777 文件夹chmod 777

相关文章

网友评论

      本文标题:在centOS上使用php5+sqlite3遇到了问题的部分记录

      本文链接:https://www.haomeiwen.com/subject/scozsktx.html