开发者

Help With PDO Query

开发者 https://www.devze.com 2023-03-04 16:13 出处:网络
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.

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 AccountEmai开发者_如何学编程l=?";
$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


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";


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

0

精彩评论

暂无评论...
验证码 换一张
取 消