Jump to content

[SOLVED] PDO Prepared Statement - Strange Problem


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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.