0
我需要控制谁输入每个子页面,并将这些信息插入到MySQL中。我有MYSQL表,它将得到的信息(用户ID,子页面,子页面,日期时间)。创建记录列表并在稍后插入PHP MYSQL
function logstore(){
global $DB, $USER, $CFG;
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')
=== FALSE ? 'http' : 'https';
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['SCRIPT_NAME'];
$currentUrl = $protocol . '://' . $host . $script;
$newsurl = $CFG->wwwroot.'/news/view.php';
$produrl = $CFG->wwwroot.'/prod/view.php';
$materialurl = $CFG->wwwroot.'/material/index.php';
$datetime = date_create()->format('Y-m-d H:i:s');
$records = new stdClass();
$records->userid = $USER->id;
if($currentUrl == $newsurl){
$records->activity = 'news';
$records->activityid = $_GET['id'];
}elseif ($currentUrl == $produrl){
$records->activity = 'prod';
$records->activityid = $_GET['id'];
}
elseif ($currentUrl == $materialurl){
$records->activity = 'material';
$records->activityid = $_GET['id'];
}
$records->datetime = $datetime;
$DB->insert_record('logstore', $records);}
林呼吁/news/view.php,/prod/view.php,/material/index.php顶部此功能。
它的工作正常,但我需要优化一点。有什么方法可以在数据库空闲时插入这些记录,或创建列表并每小时插入它们?
//编辑
我试图延迟插入,但它不是我的DB :(