PDO prepare()仅在一台服务器上失败

时间:2018-04-02 16:26:00

标签: php mysql nginx

以下代码:

let chosenIpAddress = "";

function  chosenTank(tank) {
    socket.emit('chosen tank', tank);
    console.log('Tank', tank);
    chosenIpAddress = tank.IpAddress;
}

export {
    chosenIpAddress,
};

我的在线服务器出现以下错误:

class Database {
    (...)
    public function query($query){
        $this->stmt = $this->dbh->prepare($query);
    }
    (...)
}

尽管完全相同的代码(镜像)在我的本地服务器上运行良好。我无法在2018/04/02 15:16:14 [error] 3472#3472: *3 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to a member function prepare() on null in /var/www/html/example.com/public_html/includes/pdodatabaseconnect.php:38 Stack trace: #0 /var/www/html/example.com/public_html/index.php(52): Database->query('SELECT * FROM s...') #1 {main} thrown in /var/www/html/example.com/public_html/includes/pdodatabaseconnect.php on line 38" while reading response header from upstream, client: XX.XXX.XXX.XXX, server: example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "example.com" 版本中看到任何会产生这种不同结果的PDO差异。有一些在线修改类似类来修复问题的建议,但这似乎与大锤有关 - 代码在带有镜像文件的另一台服务器上工作,在另一台服务器上运行不同的项目,但完全相同的数据库类文件。

我不确定当涉及的版本差异很小时,服务器配置可能会对执行代码产生什么样的差异,而且我无法发现可能反映错误的任何更改。看到。

服务器:

本地(MAMP)

PHP:7.2.1 / MySQL:5.6.38 / nginx:1.13.2

在线(Ubuntu 16.04)

PHP:7.0.28 / MySQL:5.7.21 / nginx:1.10.3

1 个答案:

答案 0 :(得分:0)

虽然忽略了一个愚蠢的事情,但在指出数据库密码不正确的问题时,错误是非常迟钝的。我会理解身份验证错误。

我复制了所有文件和配置这一事实意味着我对网站的相同性过于自信。但是,我已经在每个数据库上建立了一个包含不同用户帐户的数据库。