dongxiang3648 2012-05-26 11:57
浏览 101
已采纳

PDO不起作用。 我无法从PHP访问sqlite3文件。

I use php+ apache on Fedora 16 fc16.x86_64. I'm learning php and sqlite3 (using PDO). But my code doesn't work whatever.

<?php
    try {
    $db = new PDO('sqlite:./z4.db');
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $db->prepare('SELECT * FROM users;');
    $posts = $db->execute();

        echo "test test";
        echo '<ul>';
        while ($post = $posts->fetchObject()) {
        echo '<li>' . $post->content . '</li>';
        }
        echo '</ul>';


    } catch (Exception $e) {
    die($e);
    }
?>

sqlite 3 is OK, database file is ok,

Output of php -m:

apc
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
json
libxml
mbstring
mcrypt
memcache
memcached
mhash
mongo
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zip
zlib

output of rpm -qa | grep php:

php-pecl-apc-3.1.9-2.fc16.x86_64
php-pgsql-5.3.11-1.fc16.x86_64
php-gd-5.3.11-1.fc16.x86_64
php-5.3.11-1.fc16.x86_64
php-pear-1.9.4-5.fc16.noarch
php-pdo-5.3.11-1.fc16.x86_64
php-pecl-mongo-1.2.10-1.fc16.x86_64
php-common-5.3.11-1.fc16.x86_64
php-devel-5.3.11-1.fc16.x86_64
php-cli-5.3.11-1.fc16.x86_64
php-mbstring-5.3.11-1.fc16.x86_64
php-mysql-5.3.11-1.fc16.x86_64
php-mcrypt-5.3.11-1.fc16.x86_64
php-pecl-memcached-1.0.2-6.fc16.x86_64
php-xml-5.3.11-1.fc16.x86_64
php-pecl-memcache-3.0.6-1.fc16.x86_64
php-pecl-igbinary-1.1.1-1.fc16.x86_64

After adding some extensions to php.ini it is warning: Module 'xyz' already loaded on Unknown 0... so I removed them.

  • 写回答

1条回答 默认 最新

  • douzui6173 2012-05-26 15:58
    关注

    When you execute php via the command line, you don't generally execute the same php binary that your webserver runs. They can be different versions, and almost always have different php.ini and configs.

    Use phpinfo() from a script run through the webserver. Use that to find a correct php.ini file to edit, then restart the webserver to make sure settings update.

    turn on display_errors and set error_reporting to E_ALL

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况