檢查下面的代碼,我有以下問題:最後兩個參數在SQL語句中是動態的,我怎麼可以讓memcache獲得正確的參數而不僅僅是? ?,只顯示我?添加第二個變量$ sql1 =「SELECT id title vtext FROM tpost ORDER BY id desc LIMIT $ var1,$ var2」; ?或者提供更好的解決方案?Memcache&Mysqli準備了語句問題
$sql = "SELECT id, title, vtext FROM tpost ORDER BY id desc LIMIT ?, ?";
$content = $memcache->get($sql);
if($content == null) {
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('ii', $offset, $rowsperpage);
$stmt->execute();
$stmt->bind_result($r_id, $r_title, $r_vtext);
while ($stmt->fetch()) {
$data[] = array('id' => $r_id, 'title' => $r_title, 'vtext' => $r_vtext);
}
$stmt->close();
$memcache->set($sql,$data,0,$cache_time);
}
謝謝您的幫助