Jump to content

[SOLVED] PDO Prepared Statement - Strange Problem


skepp

Recommended Posts

Hello, I'm trying a simple SELECT statement with PDO (MySQL in the back) and stumbled onto a problem.

 

Here's my code:

// query
$q = "SELECT * FROM user WHERE username = :username AND password = :password";
$bindings = array(":username"=>"testuser", ":password"=>"here_comes_a_md5_hash");
$result = $DB->query($q, $bindings);
if($row = $result->fetch(PDO::FETCH_ASSOC)) {
   // do something
}

 

And in the database class I do a PDO->prepare() and some bindParams, execute() ect.

 

So..this works fine as long as I just use :username OR :password, but not with both in the query. I'm getting crazy here. If I change the query and i.e. hardcode the password = 'password-hash' OR the username = 'testuser' it works as it should and retrieves the data. But if I change the query back to the example above, it doesn't work. I get no error, just no result back. From the tests I know that both username and password are correct, so where is my error, if there is one?

 

anyone?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.