dptj13337 2015-11-04 10:50
浏览 41

SQLite execute()通过Apache工作但不通过PHP CLI工作?

I have a query that I am running in PHP 5.5.26 to access some information in a SQLite database:

$query = 'SELECT `filename` ';
$query .= 'FROM `history` ';
$stmt = $link->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$filename = $row['filename'];

So through Apache I can view the script in my browser and get a result, it works.

If I try to run this script using PHP CLI from a shell:

php script.php

I get:

PHP Fatal error:  Call to a member function execute() 
on a non-object in script.php on line 4

Line 4 is: $stmt->execute();

So through the browser client and Apache it works but when I try to do this via CLI it does not.

Usually CLI will use a different php.ini file to what is being used by Apache but in my case and because of the device in use CLI uses the same php.ini file as Apache. So when I do php --ini via CLI I get:

Configuration File (php.ini) Path: /etc/php/apache2-php5
Loaded Configuration File:         /etc/php/apache2-php5/php.ini

Indeed, it's the same php.ini file that Apache is using. When I evoke phpinfo via CLI php -i it gives me the following which stands out:

PDO

PDO support => enabled
PDO drivers => mysql, sqlite

pdo_mysql

PDO Driver for MySQL => enabled
Client API version => 5.5.43-MariaDB

Directive => Local Value => Master Value
pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock

pdo_sqlite

PDO Driver for SQLite 3.x => enabled
SQLite Library => 3.8.6


sqlite3

SQLite3 support => enabled
SQLite3 module version => 0.7-dev
SQLite Library => 3.8.6

Directive => Local Value => Master Value
sqlite3.extension_dir => no value => no value

So SQLite is installed and enabled, the PDO module for SQLite is installed and enabled.

And this is now where I am stuck. Why would it work in Apache but not work via PHP CLI? Any ideas or suggestions would be greatly appreciated, thank you in advance!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?