I'm creating a PDO Login class to use on my projects, but since I'm new to it I'm not being able to bind parameters to a prepared sql statement. Here's the function that is ment to do it :
include_once('connection.php');
class User{
protected $db;
public function __construct(){
$oConnection = new Connection;
$this->db = $oConnection->getConnection();
//var_dump($this->db);
}
public function Login($name, $pass){
if(!empty($name) && !empty($pass)){
$st = $this->db;
$st->prepare("SELECT * FROM users WHERE user_name=? and user_password=?");
$st->bindParam(1, $name);
$st->bindParam(2, $pass);
$st->execute();
var_dump($st);
if($st->rowCount == 1){
echo "User verified, Acces granted.";
}else{
echo "Incorrect username or password.";
}
}else{
echo "Please fill in the entire form";
}
}
}
And here is the Connection :
class Connection{
protected $db;
//Construct
public function Connection(){
$conn = NULL;
try{
$conn = new PDO("mysql:host=localhost;dbname=<db_name>", "<db_user>", "<db_pass>");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e){
echo 'ERROR: ' . $e->getMessage();
}
$this->db = $conn;
}
public function getConnection(){
return $this->db;
}
}
I am Receiving the following error :
Fatal error: Call to undefined method PDO::bindParam() in ......... on line 22
If someone can help me out a bit that would be great, I really want to get to know PDo better.