Chris
Chris

Reputation: 167

Help With PDO Query


I am trying to create a query that will compare an email with ones from a table and return the amount of matches it finds.

What I Have So Far

$checkMail = $this->_filteredData['AccountEmail'];
$query = "SELECT count(*) FROM AccountDetails WHERE AccountEmail=?";
$values = array($checkMail);
$this->_DBO->runSelectQuery($query, $values, true);

/////// This is In A Different Class
public function runSelectQuery($query, $values = array(), $returnResults = false)
{
    $sth = $this->_DBO->prepare($query);
    $sth->execute($values); 
}

Finishing Up

My problem is that I don't know how to finish it up, I need to work out how many matches it found.
There will only be 1 match if any as emails are unique in the table so it will either return 0 or 1. If it returns one I also need to get the other data from the table, its password value and its id number.

I don't know if this is the right way to go about doing this so any feedback will be appreciated.
Thanks
Chris

Upvotes: 0

Views: 80

Answers (2)

akc42
akc42

Reputation: 5001

you need to use a

$count = $sth->fetchColumn()

to get the return from the select statement

I am not sure what you want $returnResults to have in it but this might just be what I put in the $count variable

Upvotes: 1

Chris Yallop
Chris Yallop

Reputation: 56

Just specify the password and ID value in the same query. It will either return a result or it won't if there is no match.

$query = "SELECT id, password FROM AccountDetails WHERE AccountEmail=? LIMIT 1";

Upvotes: 1

Related Questions