我想將我的照片管理系統從XML遷移到MySQL並擴展我當前系統的功能。MySQL - 照片評論,投票,關鍵字,++,在單表中?
基本上,我在MySQL中很少有東西,而在xml文件中很少。這種情況現在看起來是這樣的:
「news.xml」 - 單個文件:
存儲有我的網站上所有新聞(新上傳,投票及評析)和XML的結構:<all_news> <photos> <image image_name="photo1.jpg" path="my_photos/" date="12.12.12" info="just Uploaded!" /> </photos> <comments> <image image_name="photo1.jpg" path="my_photos/" date="12.12.12" info="just Commented!" /> </comments> <votes> <image image_name="photo1.jpg" path="my_photos/" date="12.12.12" info="just Voted!" /> </votes> </all_news>
「photo1.xml」, 「photo2.xml」, 「photo3.xml」 ... - 多個文件:
如果有人對我的照片留言,這些文件是動態創建的。例如,如果有人評論我的照片,PHP腳本,自動格式創建「photo_name.xml」文件:<comments> <comment sender='John' text='nice photo!' who='user' date='22.12.12'/> </comments>
「投票」 - MySQL表:
有存儲的所有選票,結構id: "photo1.jpg"
vote: 5
- :表
現在我想所有這些事情合併成一個單一的MySQL數據庫表,所以每次當照片被加載時間 - 拉從一個數據庫表中的這些照片信息(而不是加載一些XML的和DB在同一時間)...
所以我的問題是:
什麼表結構是最好的在這種情況下最簡單的工作(拉數據,移動,刪除,編輯,添加,排序...)?
我應該使用unique id =「photo.jpg」和多維數組來保存單個文件中的所有內容嗎?例如:
uid: photo_name.jpg
path: my_photos/
isNewPhoto: array[true, array[info:"just uploaded!"][date:"12.12.12"]] (multi-dimensional array ??)
isNewComment: array[true, array[info:"just commented!"][date:"12.12.12"]] (multi-dimensional array ??)
isNewVote: array[true, array[info:"just Voted!"][date:"12.12.12"]] (multi-dimensional array ??)
votes: 1,5,3,2
votesIP: 123123123,123123123,123123123
comments: array[array[sender][comment][date][who]]] (multi-dimensional array ??)
如果您想使用單個表格,最好使用非關係系統(如mongodb)。 – 2012-07-13 15:38:56
爲什麼把所有東西放在一張桌子上?您目前正在使用單獨的文件獲取新聞,評論和投票,爲何不復制該文件? – andrewsi 2012-07-13 15:40:39
數據庫的關鍵特徵是它本質上是關係型的,它們之間有多個關係。一張照片可以有很多評論,很多票(還有選民)。建立關係模型比把所有數據都放在一個表中更合理... – 2012-07-13 15:42:01