How can I check if a MySQL row exists using PHP? And then return true or false?
I tried this:
// Does a game with that url-name exist?
public function nameExist() {
return $this->db->execute('SELECT COUNT(*) FROM `main_games` WHERE `url`=?', array($this->getSubdomain()));
}
Here is the source of the class:
http://pastebin.com/p17gUEPA
And here is the source of the hook where I run this class from:
http://pastebin.com/WjSNLCMd
Take a look at what execute returns:
So even if there are 0 rows but executing the statement succeded, then you will still get a true. What you can do is use fetchColumn() to actually get the number of rows and return that. Something like this: