TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-21-2009, 09:04 AM   #1 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default Admin Settings Table

I want to build a mysql table to store admin settings for my website. Initially I want to store a setting for:

Website down for maintenance
Switch debug mode on
switch google analystics on
set server timezone

Basically key settings which will have a Y/N setting. As this table will be called once every time a page is built I need to structure it in the most sensible way. I'd call the table and intend to do one read on the entire table (4 rows) and then instantiate an object with 4 properties to handle the settings. Any suggestions - is this the most efficient way to do it?
captainmerton is offline  
Reply With Quote
Old 11-21-2009, 04:56 PM   #2 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

You can always put it in one row, and use each setting as a heading.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 11-21-2009, 08:38 PM   #3 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

mysql Code:
CREATE TABLE IF NOT EXISTS `my_options` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL DEFAULT '',
  `value` varchar(65535) NOT NULL,
  PRIMARY KEY (`id`,`name`)
) ENGINE=InnoDB

No sense in trying to mash everything into one row if you're going to use a database to begin with. Then you have to jump through hoops after selecting the data just to make it usable.

If you're using MySQL < 5.0.3 you would have to change the longer varchar to a text or longtext - this is of course assuming you want to eventually store long options values or arrays in that column. If all your options are now and forever only going to be true|false (on/off), then you could use the following instead;

mysql Code:
`value` enum('1') DEFAULT NULL,
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
feedback on my class please frostyboy33 Advanced PHP Programming 7 10-22-2012 09:12 AM
Databse structure Village Idiot TalkPHP Developer Team 3 01-16-2009 10:31 PM
This project has begun! Village Idiot TalkPHP Developer Team 40 01-01-2009 04:29 AM
Lookups table drewbee Advanced PHP Programming 0 07-15-2008 08:21 PM
How to check if a table exists? Haris General 8 09-19-2007 09:04 PM


All times are GMT. The time now is 11:42 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design