PHP에서 새로운 것을하려고합니다. MYSQL 데이터베이스에서 행을 계산합니다. 그러나 echo $rows
을 입력하자마자 오류가 계속 발생합니다.PHP7에서 mysql_num_rows가 작동하지 않습니다.
누군가 나를 도울 수 있습니까?
내 로그인 코드는 다음과 같습니다.
<?php
'include('classes/DB.php');
if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if (DB::query('SELECT username FROM users WHERE username=:username', array(':username'=>$username))) {
// if (DB::query('SELECT token FROM login_tokens WHERE user_id=1')<=5) {
if (password_verify($password, DB::query('SELECT password FROM users WHERE username=:username', array(':username'=> $username))[0]['password'])) {
echo 'Logged in!';
$query = DB::query('SELECT * FROM login_tokens WHERE user_id=:user_id', array(':user_id'=>$user_id));
$rows = mysql_num_rows($query);
echo $rows;
$cstrong = True;
$token = bin2hex(openssl_random_pseudo_bytes(64, $cstrong));
$user_id = DB::query('SELECT id FROM users WHERE username=:username', array(':username'=>$username))[0]['id'];
DB::query('INSERT INTO login_tokens VALUES (0, :token, :user_id)', array(':token'=>sha1($token), ':user_id'=>$user_id));
setcookie("SNID", $token, time() + 60 * 60 * 24 * 7, '/', NULL, NULL, TRUE);
setcookie("SNID_", '1', time() + 60 * 60 * 24 * 3, '/', NULL, NULL, TRUE);
} else {
echo 'Incorrect Password!';
}
// } else {
// echo 'You already logged in on 5 different devices!'
// }
} else {
echo "User not registered! Create account <a href='http://follome.ddns.net/create-account.php'>here</a>!";
}
}
?>
<h1>Login to your account</h1>
<form action="login.php" method="post">
<input type="text" name="username" value="" placeholder="Username ..."><p />
<input type="password" name="password" value="" placeholder="Password ..."><p />
<input type="submit" name="login" value="Login">
</form>
그리고 내 DB 클래스 :
<?php
class DB {
private static function connect() {
$pdo = new PDO('mysql:host=127.0.0.1;dbname=socialnetwork;charset=utf8', 'root', 'Daan0109');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
}
public static function query($query, $params = array()) {
$statement = self::connect()->prepare($query);
$statement-> execute($params);
if (explode(' ', $query)[0] == 'SELECT') {
$data = $statement->fetchAll();
return $data;
}
}
}
저희가 제공하는 오류를 알려주십시오. – Wndrr