0

I have an application that create child's gifts applications, and every application owner can add own gifts, right now i'm storing gifts in a php array :

<?php
$gifts_array = array(
array(>4,"Flower",>250,"5_250.jpg",301),
array(1,"a Good Day",30,"3_30.jpg",153),
array(2,"cat",10,"3_10.gif",139),
array(3,"batman",20,"2_20.jpg",101),
array(11,"White Wolf",100,"11_100.jpg",5),
array(10,"crazy cat",30,"10_30.gif",2),
array(8,"Gift",100,"6_100.jpg",2),
array(12,"Car",120,"12_120.jpg",1),
array(9,"cat 2",30,"9_30.gif",1),
array(7,"2Pac",500,"3_500.jpg",0),
array(6,"Outlawz",500,"4_500.jpg",0)
);
?>

I need to update gift counter every time sent, so i have to do a loop to find the gift then increment and write the whole array in the file.

It is good to create this Array like that :

    '100'=>array('gname'=>"Flower",'gpoints'=>250,'gpic'=>"5_250.jpg",'gviews'=>301),
     100 is the Gift ID.

What is the best solution : - Create for every application a MySQL table ? - Use one Table for all applications ? - Use one MySQL table to store all apps gifts and cache MySQL results for each application after Gift INSERT/UPDATE/DELETE ?

3
  • One table per app isn't a bad idea. I got an app that uses a couple of hundreds of tables... Commented Feb 13, 2011 at 21:28
  • I already used that for storing users, and some logs, using cache for this solutions is good ??? Commented Feb 13, 2011 at 21:32
  • MySQL has a query cache built in. Commented Feb 13, 2011 at 21:48

2 Answers 2

3

Just create one table with the same number of columns, plus one identifying which "application" it corresponds to. Don't create a new identical table for each app, and don't keep reading/writing from a text file, both are concurrency and maintenance nightmares.

Sign up to request clarification or add additional context in comments.

4 Comments

every application can upload a maximum of 100 gifts, I think SELECT's queries from a table with more than 300k rows is slow ?
No, not unless you consider single digit milliseconds slow. This webpage involves many queries to tables with millions of rows, is that slow? Define an index on the application column and it doesn't even look at the table, just the index.
If you're using MyISAM storage engine then storing all your applications in one table will cause concurrency issues. InnoDB won't suffer as badly. EDIT: However, even using the MyISAM storage engine is better than the text file approach
That's not really true either. I have sites that write into MyISAM tables over 300 times per second. If any concurrency on MyISAM was automatically poor performing then MySQL would never have survived as a popular platform when InnoDB usage was unavailable/rare.
0

Use a single table

//Create a table to hold all your info
CREATE applications (id INTEGER AUTO INCREMENT, gname VARCHAR(255), gpoints INTEGER, gpic VARCHAR(255), gviews INTEGER);

//Increment the number of views
UPDATE applications SET gviews=gviews+1 WHERE gname='Flower'

//Get the names of all the applications (replace gname with what you want to get or * for all)
SELECT gname FROM applications

//Initially add the entries into applications
INSERT INTO applications (gname, gpoints, gpic, gviews) VALUES ('Flower', 250, '5_250.jpg', 301)

1 Comment

Every application have an ID stored in Applications table, and every app can upload it own gifts :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.