1

I'm trying to make the PDO query below working, but somehow it doesn't. This is how far i mine brain exploded! Is there somebody who can say what i'm doint wrong?

$dbh = new PDO("mysql:host=localhost;dbname=databasename", "user", "pass"); $stmt = $dbh->prepare("SELECT * FROM `something` WHERE `email`=':email' and `name`=':name'"); $stmt->bindParam(':email', '[email protected]',PDO::PARAM_STR); $stmt->bindParam(':name', 'name',PDO::PARAM_INT); $stmt->execute(); if($stmt->rowCount() == 1) { echo "row count 1"; } else if ($stmt->rowCount() == 0) { echo "row count 0"; } else if ($stmt->rowCount() > 1) { echo "row count greater then 1"; } 

1 Answer 1

1

Single quotes (') denote string literals in SQL, so the prevent PDO from parsing inside them. If you want to use bind variables, you should remove the quotes (don't worry, PDO will properly handle them as strings):

$stmt = $dbh->prepare ("SELECT * FROM `something` WHERE `email`=:email and `name`=:name"); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.