0
你好,我希望將下面的代碼遷移到mysqli。請幫忙,這是登錄功能。第一個函數從數據庫獲取user_id
,而第二個函數檢查username
和password
是否與user_id
中的該用戶匹配。mysql查詢到mysqli查詢
function user_id_from_username($username){
$username = sanitize($username);
return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, 'user_id');
}
function login($username, $password){
$user_id = user_id_from_username($username);
$username = sanitize($username);
$password = md5($password);
$query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'");
return (mysql_result($query, 0) == 1)? $user_id : false;
}
請避免mysql_ *功能,因爲這些都是現在在PHP 7 –
PHP版本棄用請sepcify? –
格式正確請 – nogad