skepp Posted August 13, 2009 Share Posted August 13, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/170173-solved-pdo-prepared-statement-strange-problem/ Share on other sites More sharing options...
skepp Posted August 13, 2009 Author Share Posted August 13, 2009 Oh btw. forgot to mention the mysql version: mysql Ver 14.12 Distrib 5.0.75 Quote Link to comment https://forums.phpfreaks.com/topic/170173-solved-pdo-prepared-statement-strange-problem/#findComment-897695 Share on other sites More sharing options...
skepp Posted August 13, 2009 Author Share Posted August 13, 2009 Ok, changed from bindParam() to bindValue() and now it works as it should... Quote Link to comment https://forums.phpfreaks.com/topic/170173-solved-pdo-prepared-statement-strange-problem/#findComment-897717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.