Forum Moderators: open
A simple question probably..
I want to create a mysql table to store email addresses of people who don't want to receive emails.
The table should only have to store the email addresses, no other information such as a member id is needed.
I will have to do a SELECT query on the table quite often to see if an email address exists in the table.
For the past few years, I have always used this:
CREATE TABLE `em_opt_out` (
`em_id` mediumint(8) unsigned NOT NULL auto_increment,
`email` varchar(70) NOT NULL default '',
PRIMARY KEY (`em_id`)
) ENGINE=MyISAM;
and then the mysql select query in PHP:
$total = mysql_result(mysql_query("SELECT COUNT(em_id) FROM em_opt_out WHERE email='".quote_smart($email)."'"),0);
Although this works perfectly fine, I have the feeling it is not the most efficient, since I've defined the em_id auto-increment, but never use it.
What would you guys suggest? Is it better to do this for example?
CREATE TABLE `em_opt_out` (
`email` varchar(70) NOT NULL default '',
PRIMARY KEY (`email`)
) ENGINE=MyISAM;
and then the mysql select query in PHP:
$total = mysql_result(mysql_query("SELECT COUNT(email) FROM em_opt_out WHERE email='".quote_smart($email)."'"),0);
Thanks in advance for your help!
There's certainly nothing wrong with the original design. At this point, I'm not sure it's worth the added work to change things.
The extra error checking for inserting a new record in the second example wouldn't have been a problem though, an insert query would be very rare, whereas the select would be very frequent.
Thanks again!