我運行下面的代碼時出現此錯誤。我通常使用msql函數,但我試圖改用PDO。哪裏不對 ?使pdo ::查詢靜態
致命錯誤:非靜態方法PDO ::查詢()不能靜態調用在線14
<?php
if(isset($_POST['username']) AND isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$password_hash = md5($password);
if (!empty($username) AND !empty($password)) {
$query = "SELECT 'id' FROM `userdatabase` WHERE 'email'='$username' AND 'password'='$password_hash'";
if($query_run = PDO::query($query)){
$query_num_rows = PDO::rowcount($query_run);
if ($query_num_rows==0){
echo 'invalid password/username';
} else {
echo 'Username/password = correct';
}
}
} else {
echo 'You must enter a password..';
}
}
?>
1件事要記住:結果認爲,所謂的PDOStatement對象,而不是查詢的實際結果,以訪問這些:'$ actualResults = $ result-> fetchAll(PDO :: FETCH_ASSOC);',或者1乘1'while($ row = $ results-> fetch(PDO :: FETCH_ASSOC)){echo $ row [ '更遠'];}' –