wampserver,win2012r,php,环境中,mysqli扩展问题

我在问题描述的环境中,会出现下面的问题,

Fatal error: Uncaught Error: Class 'mysqli' not found in D:\wamp64\www\extension\db\conn.php:6 Stack trace: #0 D:\wamp64\www\extension\db\model.php(13): olMySQLi->__construct() #1 D:\wamp64\www\extension\loginProcess\login.php(259): dbQuery('SELECT * FROM `...') #2 D:\wamp64\www\extension\loginProcess\login.php(133): loginProcess('333', '86e7991b05d95b2...', 'cleanShelf') #3 D:\wamp64\www\extension\loginProcess\login.php(42): manualLogin('333', '3333', Object(stdClass), 10, '../../extension...', 'cleanShelf') #4 {main} thrown in D:\wamp64\www\extension\db\conn.php on line 6

同时,phpmyadmin也提示缺少mysqli扩展。

但是这个只有在win2012上,且使用下面代码才会出现,

<?php
final class olMySQLi {
    private $connection;

    public function __construct() {
        $this->connection = new mysqli("127.0.0.1","root","","extension_user",NULL) or die("database connect failure");

        if ($this->connection->connect_error) {
            throw new \Exception('Error: ' . $this->connection->error . '<br />Error No: ' . $this->connection->errno);
        }

        $this->connection->set_charset("utf8");
        $this->connection->query("SET SQL_MODE = ''");
    }

    public function query($sql) {
        $query = $this->connection->query($sql);

        if (!$this->connection->errno) {
            if ($query instanceof mysqli_result) {
                $data = array();

                while ($row = $query->fetch_assoc()) {
                    $data[] = $row;
                }

                $result = new stdClass();
                $result->num_rows = $query->num_rows;
                $result->row = isset($data[0]) ? $data[0] : array();
                $result->rows = $data;

                $query->close();

                return $result;
            } else {
                return true;
            }
        } else {
            throw new \Exception('Error: ' . $this->connection->error  . '<br />Error No: ' . $this->connection->errno . '<br />' . $sql);
        }
    }

    public function escape($value) {
        return $this->connection->real_escape_string($value);
    }

    public function countAffected() {
        return $this->connection->affected_rows;
    }

    public function getLastId() {
        return $this->connection->insert_id;
    }

    public function connected() {
        return $this->connection->ping();
    }

    public function __destruct() {
        $this->connection->close();
    }
}

经过测试,在windows10上使用同样的代码,同样版本wamp是没有任何问题的。

在win2012上使用,自带testmysql.php,也是可以正常使用mysqli扩展的。

只有在win2012,且使用上述代码的时候,才会出现mysqli扩展缺失问题。
而且,一旦出现后,哪怕重启wamp,这个问题也会一直存在。


2020-06-30问题补充,已经找到问题所在了。
由于以前出问题都是百度或者谷歌,没有看日志的习惯,所以花了很久才找到问题。

我去找日志后发现,是因为php.ini的设置,在php7之后,做了改动。

这次问题是php error report引起的,以前只需要修改成default,就可以了。
现在直接修改default,会引起错误。
我看日志里报了错,php.ini第107行,有&符号。
以前这个&符号,是用来排除warning、notice等等级别的系统提示的。
现在版本的php.ini设定,只需要在前一条设置,是采用default,还是其他值,就可以了。

总结,要习惯自己看日志找到问题所在。搜索的回答,很难匹配具体发生的问题的。

https://blog.csdn.net/donghustone/article/details/86031765