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 :(