我有一个间歇性的错误,我无法触及底部。
我的网站每天有大约9000多次登录 - 我处理Mysql中的所有会话。
每天4到5次我在php错误日志中出现以下错误块。
11:24:29 PHP警告:mysqli_real_escape_string()要求参数1为mysqli,在第43行的C:\ inetpub \ wwwroot \ apps \ shared \ sessions.php中给出null
11:24:29 PHP警告:mysqli_real_escape_string()要求参数1为mysqli,在第43行的C:\ inetpub \ wwwroot \ apps \ shared \ sessions.php中给出null
11:24:29 PHP警告:mysqli_query()要求参数1为mysqli,在第44行的C:\ inetpub \ wwwroot \ apps \ _共享\ sessions.php中给出null
11:24:29 PHP警告:mysqli_affected_rows()要求参数1为mysqli,在第45行的C:\ inetpub \ wwwroot \ apps \ _共享\ sessions.php中给出null
11时24分29秒 PHP警告:mysqli_close()要求参数1为mysqli,在第24行的C:\ inetpub \ wwwroot \ apps \ shared \ sessions.php中给出null
我无法弄清楚可能会出现什么问题,因为我一直认为它是否会发生任何重大事件。
<?php
$config = array();
$config["dbuser"] = 'myusername'; //database username
$config["dbpass"] = 'mypassword'; //database password
$config["database"] = 'mydatabase'; //database name
$config["dbloc"] = '127.0.0.1'; //database location
$dbc = NULL;
$garbage_timeout = 151200; // 3600 seconds = 60 minutes = 1 hour
ini_set('session.gc_maxlifetime', $garbage_timeout);
function open_session() {
global $dbc, $config;
$dbc = mysqli_connect($config["dbloc"], $config["dbuser"], $config["dbpass"], $config["database"]);
return true;
}
function close_session() {
global $dbc;
return mysqli_close($dbc);
}
function read_session($sid) {
global $dbc;
$q = "SELECT data FROM sessions WHERE id='".mysqli_real_escape_string($dbc, $sid)."'";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) == 1) {
list($data) = mysqli_fetch_array($r, MYSQLI_NUM);
return $data;
} else {
return '';
}
}
function write_session($sid, $data) {
global $dbc;
$q = "REPLACE INTO sessions (id, data) VALUES ('".mysqli_real_escape_string($dbc, $sid)."', '".mysqli_real_escape_string($dbc, $data)."')";
$r = mysqli_query($dbc, $q);
return mysqli_affected_rows($dbc);
}
function destroy_session($sid) {
global $dbc;
$q = "DELETE FROM sessions WHERE id='".mysqli_real_escape_string($dbc, $sid)."'";
$r = mysqli_query($dbc, $q);
$_SESSION = array();
return mysqli_affected_rows($dbc);
}
function clean_session($expire) {
global $dbc;
$q = "DELETE FROM sessions WHERE DATE_ADD(last_accessed, INTERVAL ".(int) $expire." SECOND) < NOW()";
$r = mysqli_query($dbc, $q);
return mysqli_affected_rows($dbc);
}
session_set_save_handler('open_session', 'close_session', 'read_session', 'write_session', 'destroy_session', 'clean_session');
?>