本文介紹了調用未定義的方法 PDO::execute()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試對頁面登錄進行編碼,但我被這個錯誤阻止了
i'm trying to code a page login but i was stopper at this error
請告訴我這里的錯誤
<?php
@session_start();
include("../../connexion/connexion.php");
class login_class {
public $user;
public $password;
public $connexion;
public function check_login() {
try {
$cn = new class_connect();
$this->connexion = $cn->connect(null);
$result = $this->connexion->execute("select * from user where username='$this->user' and password='$this->password'");
$data = $result->fetchAll(PDO::FETCH_OBJ);
if (!empty($data[0]->id_user)) {
return true;
}else {
return false;
}
}catch(PDOException $ex) {
echo $ex->getMessage();
}
}
public function __construct($user) {
if($user){
$this->user = $user["username"];
$this->password = $user["password"];
}
}
}
?>
推薦答案
->execute()
用于準備好的語句.例如
->execute()
is for prepared statements. e.g.
$stmt = $dbh->prepare('some query here');
$stmt->execute();
您正在嘗試直接在主數據庫對象上執行查詢.對于 PDO,這意味著
You're trying to execute a query directly on the main DB object. For PDO, that means
$dbh->exec('query goes here');
您真的應該查看準備好的語句.您很容易受到SQL 注入攻擊的影響,而且由于您一開始使用的是 PDO,因此基本上是不可原諒的不要編寫安全的查詢.
You really should look into prepared statements. You're vulnerable to SQL injection attacks as is, and since you're using PDO to begin with, it's basically unforgivable to NOT be writing safe queries.
這篇關于調用未定義的方法 PDO::execute()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!