cmor Posted July 16, 2010 Share Posted July 16, 2010 Hopefully a very simple question. Looking to see if ->execute on a prepared SELECT statement returns any results. ->execute simply returns true if it was successful (results or not). It also returns an array with a count of 1 using ->fetch Here's where I'm at: public static function authenticate($user='',$password='') { global $db; $sql = 'Select * FROM users WHERE username = :user AND password = :password LIMIT 1'; $stmt = $db->prepare($sql); $stmt->bindValue(':user',$user); $stmt->bindValue(':password',sha1($password)); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); return count($row)!=1 ? array_shift($row) : false; } It works but seems awkward. Link to comment https://forums.phpfreaks.com/topic/207900-check-if-preparedstatement-execute-has-returned-any-select-results/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.