0
我正在創建自己的評論系統,並決定是時候遷移到MySQLi。MySQLi準備對帳單格式
我想知道的是 - 我是否正確地做到了這一點?
我是否在必要時釋放和關閉結果?我錯過了什麼?
(?又是什麼使語法在這個網站突出代碼示例按鈕不執行任何操作)
$mysqli = new mysqli('localhost', 'username', 'password', 'comments');
if($stmt = $mysqli -> prepare("INSERT INTO comments (topid, body, user, active) VALUES (?, ?, ?, ?)"))
{
$stmt->bind_param('isii', $id, $comment, $userid, $mod);
$stmt->execute();
$stmt->close();
}
else
{
$mysqli->close();
echo '{"status":0,"error":'.json_encode('Database Error - Please try again.').'}';
return;
}
$mysqli->close();
,這裏是我做了我的「而」循環:
$comments = array();
$mysqli = new mysqli('localhost', 'username', 'password', 'comments');
$mysqli->set_charset('utf8');
if($stmt = $mysqli -> prepare("SELECT user.id as userid, user.name, comments.id, comments.body, comments.dt FROM comments JOIN user ON comments.user = user.id where comments.postid = ? and comments.topid=0 and comments.active=1 ORDER BY comments.id DESC Limit ?, ?"))
{
$stmt->bind_param('iii', $postid, $offset, $limit);
$stmt->execute();
$res = $stmt->get_result();
$stmt->close();
}
while($row = $res->fetch_assoc())
{
$comments[] = new Comment($row);
}
$res->free();
$mysqli->close();
return $comments;
有一些事情突破我相信。 –
您選擇的標籤使您的問題顯得不那麼重要。使用的最受歡迎的標籤,您擁有的視圖越多。雖然這可能不是一個好處 –