Melvin Langvik Melvin Langvik - 3 months ago 31
MySQL Question

Non-static method PDO::quote() cannot be called statically,

Error i get from WAMP

$username = $_POST['username'];
$password = $_POST['password'];


$db = new PDO('mysql:host='.$DB_HOST.';dbname='.$DB_DATABASE.'', ''.$DB_USER.'', ''.$DB_PASSWORD.'');

$query = $db->query("SELECT * FROM login_details WHERE username=:username AND password=:password");
$query->bindValue(':username', $username, PDO::PARAM_STR);
$query->bindValue(':password', $password, PDO::PARAM_STR);
$query->execute();
$row_count = $query->rowCount();


Trying to do a simple username and PW check from an database..
I'm beyond the point of frustrated...

Answer

Use prepare instead.

$username = $_POST['username']; 
$password = $_POST['password'];

$db = new PDO('mysql:host='.$DB_HOST.';dbname='.$DB_DATABASE.'', ''.$DB_USER.'', ''.$DB_PASSWORD.'');

$query = "SELECT * FROM login_details WHERE username=:username AND password=:password";
$statement = $db->prepare($query);
$statement->bindValue(':username', $username, PDO::PARAM_STR);
$statement->bindValue(':password', $password, PDO::PARAM_STR);


$statement->execute();
$row_count = $statement->rowCount();

echo $row_count;

More info here.

Comments