安全.php
class Security {
public function sanitize($data) {
return mysql_real_escape_string($data);
}
}
?>
用户.php
<?php
class User {
private $db;
public function __construct() {
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function userExists($username) {
$username = sanitize($username);
$st = $this->db->prepare("SELECT * FROM `users` WHERE `username`=? ");
$st->bindParam(1, $username);
$st->execute();
if ($st->rowCount() == 1) {
echo "User exists";
} else {
echo 'Incorrect username or password lad';
}
}
}
?>
在我的用户存在方法中,我想使用清理方法,但我不确定在 oop 中执行此操作的正确方法。两个类都在不同的文件中。任何帮助表示赞赏。