MySQL Forums
Forum List  »  Newbie

Re: Help with the best table layout for message board
Posted by: Rick James
Date: November 29, 2009 06:14PM

VARBINARY(15) suffices for IPv4. 'nnn.nnn.nnn.nnn'

CREATE TABLE BlackList (
   ip VARBINARY(15) NOT NULL,
   PRIMARY KEY (ip)
);
SELECT COUNT(*) FROM BlackList WHERE ip = ? ;
In PHP you will get back 0 or 1 from the SELECT; act accordingly.

I don't see the need for further normalization.

A variation; assuming your table xyz has an ip VARBINARY(15) field, and
SELECT ...,
       IFNULL(xyz.ip, 'is blacklisted') AS status
   FROM xyz
   LEFT JOIN BlackList bl  ON bl.ip = xyz.ip
The 'status' column will either be the ip address or the string "is blacklisted".

Options: ReplyQuote


Subject
Written By
Posted
Re: Help with the best table layout for message board
November 29, 2009 06:14PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.