我的网站在托管站点上,一切正常,除了我正在检查允许的 cpu 使用率。我将我的网站和数据库迁移到安装了 WAMP 的本地计算机上。
老主机: Apache版本 2.2.23 PHP版本 5.3.18 MySQL版本 5.1.66-cll
WAMP: Apache 2.4.2 PHP 5.4.3 MYSQL 5.5.24
由于某种原因,小于和大于比较运算符在我的 mysqli 准备语句中停止工作。如果我删除了 sql 语句的以下部分,那么它将返回一切正常。我还尝试手动输入日期,其中?是,并且也正确返回。
不工作 where last_update > ?
有效 where last_update > '1991-09-26 01:25:10'
这是我拥有的代码:
<?php
session_start();
$output = "You must log in to see users.";
if (isset($_SESSION['status'])){
$status = $_SESSION['status'];
$myUsername = $_SESSION['username'];
if ($status == 1){
$output = "";
require_once __DIR__ . '/db_connect.php';
$mysqli = new DB_CONNECT();
$currentTime2 = date( 'Y-m-d H:i:s', strtotime('-15 seconds'));
if ($stmt = $mysqli->prepare("select username from users where last_update > ? order by username")){
$stmt->bind_param("s", $currentTime2);
$username = "";
$stmt->execute();
$stmt->bind_result($username);
while ($stmt->fetch()){
if ($username != $myUsername){
$output = $output . "<div class='user'><div class='user-pic'></div><div class='user-name'>" . $username . "</div></div>";
}
}
$stmt->close();
}
}
}
echo $output;
?>
我从该 php 文件中得到的唯一错误是:
SCREAM: Error suppression ignored for
( ! ) Strict standards: Declaration of DB_CONNECT::connect() should be compatible with mysqli::connect($host = NULL, $user = NULL, $password = NULL, $database = NULL, $port = NULL, $socket = NULL) in C:\wamp\www\db_connect.php on line 31
Call Stack
# Time Memory Function Location
1 0.0002 254240 {main}( ) ..\onlineUsers.php:0
这是 db_connect.php 文件:
<?php
class DB_CONNECT extends mysqli{
function __construct() {
$this->connect();
}
function __destruct() {
$this->close();
}
function connect() {
require_once __DIR__ . '/db_config.php';
parent::__construct(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
if (mysqli_connect_errno()) {
printf("connect failed: %s\n", mysqli_connect_error());
exit();
}
}
function close() {
}
}
?>
请注意,如果我使用 bind_param 或只是手动输入日期时间,我会得到这个,所以这可能不是这里的原因。