I’m a newbie, and this is my first post. I hope that some day I’ll be able to help out newbies like myself. In the meantime, I thank you in advance for your replies.
Is the script below the fastest and most efficient way to check if a username and password match in a MySQL database?
If it is in fact the most efficient, what would be its equivalent:
1 - Using MySQLi using (Procedural Style).
2 - Using MySQLi using (Object Oriented Style).
3 – Using MySQLi with Prepared Statements - Object Oriented style.
4 – Using PDO with prepared statements - Object Oriented style.
$connection = mysql_connect('localhost','root','pass') or die(mysql_error());
$database = mysql_select_db("database_name",$connection);
$sql = "SELECT count(*) FROM members WHERE username = '$username' AND
password ='$password' LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_result($result, 0) > 0){
echo 'found User <br />';
}
if (mysql_result($result, 0) < 1){
echo 'username or password does not exist';
}