Getting Field from MySQL
Posted: Wed Aug 07, 2002 3:04 am
I have made a IP banning system and I stored all the banned IP addresses in the MySQL database (table called "banned_ip"). Here's the code I used:-
and I timed this script and also timed the following code:-
I have manage to work out that the bottom code takes less time to execute. But I did not have much banned IP addresses in the database. Will this change if there is a lot of banned IP addresses in the database?
Code: Select all
@mysql_connect("localhost","username","password") or die "Failed to establish connection with MySQL server";
@mysql_select_db("database") or die "Failed to select a database.";
$sql = "SELECT ip FROM banned_ip";
$temp = mysql_query($sql);
while($result = mysql_fetch_array($temp))
{
if($result == $REMOTE_ADDR)
{
echo "You're banned from the system";
mysql_close();
mysql_free_result($result);
exit();
}
}Code: Select all
$sql = "SELECT ip FROM banned_ip WHERE ip = '$REMOTE_ADDR'";
$temp = mysql_query($sql);
if($result == $REMOTE_ADDR)
{
echo "You're banned from the system";
mysql_close();
mysql_free_result($result);
exit();
}