[英]How do you create a database in mySQL Workbench that you can connect to with php?
[英]Can you do this with a database?
我將所有視頻和每個視頻的詳細信息存儲在數據庫中。 我有一些桌子:
每個視頻都有針對1080和720進行編碼的文件,並且每個視頻都再次使用三種不同的比特率進行編碼,並且每個比特率都再次由WebM和MP4進行了編碼。 因此,每個視頻條目的video_file中有六個條目。 因此,我的查詢為每個視頻返回12行。
我看到的問題是,對於每一行,所有信息都包括在內,而不僅僅是“必要”信息。 例:
| id | name | playlist | file | quality | size | type |
---------------------------------------------------------------------
1 video1 funny videos file1 3 720 MP4
1 video1 funny videos file2 2 720 MP4
1 video1 funny videos file3 1 720 MP4
1 video1 funny videos file4 3 1080 MP4
1 video1 funny videos file5 2 1080 MP4
1 video1 funny videos file6 1 1080 MP4
1 video1 funny videos file7 3 1080 WebM
1 video1 funny videos file8 2 1080 WebM
1 video1 funny videos file9 1 1080 WebM
1 video1 funny videos file10 3 720 WebM
1 video1 funny videos file11 2 720 WebM
1 video1 funny videos file12 1 720 WebM
這是示例輸出。 我認為更有效的方法是對結果進行分組,這樣一來一行就不會得到多余的信息,畢竟,您將使用PHP或使用該語言的語言對這些信息進行分組完全沒有
我認為會更有效的示例:
| id | name | playlist | file | quality | size | type |
---------------------------------------------------------------------
1 video1 funny videos file1 3 1080 WebM
file2 MP4
file3 720 WebM
file4 MP4
file5 2 1080 WebM
file6 MP4
file7 720 WebM
file8 MP4
file9 1 1080 WebM
file10 MP4
file11 720 WebM
file12 MP4
這樣,您可以輕松地設置一些與列名稱相對應的變量:
id, name, playlist, file, quality, size, type
while (record = fetchRecord)
id = record.id or id
name = record.name or name
playlist = record.playlist or playlist
file = record.file or file
quality = record.quality or quality
size = record.size or size
type = record.type or type
// Now you have filled the variables with the exact information you had in the first recordset example, but without wasting so much unnecessary bandwidth and processing power.
現在,我要添加另一個表,其中包含在視頻播放期間彈出的注釋,因此,如果視頻上有x個注釋,則每個視頻將返回12x行。
瘋了吧! 我錯過了什么嗎? 我在這里“解釋”的內容實際上可行嗎? 還是最好讓一個查詢像現在這樣,每個視頻返回12行,然后遍歷每個視頻以獲取注釋,還是什么?
這是我問題的結尾,非常感謝您通篇閱讀!
執行此操作的另一種方法是在不同的列之間使用GROUP_CONCAT
函數,並在重復的列上分組。 這將在輸出中創建一個帶分隔符的字符串列,您需要在PHP中對其進行解析; 但是,它將把行數減少到僅非分組列的唯一組合數。 例如:
select name, playlist, GROUP_CONCAT(file, '|', quality, '|', size, '|', type SEPARATOR '/') AS delimited_pairs
from video
group by name, playlist;
在上面的示例中,所得的delimited_pairs
列將使用豎線字符來分隔每個名稱/播放列表(分組列)中的每個唯一列值,並且這些唯一組合中的每個都將由正斜杠分隔。
我認為您的數據布局有問題。 您的“冗余數據”不應進入video_file
表,而應在video
表中,因為它是指視頻而不是文件的信息! 如果您例如,此數據庫方案在一致性方面也很糟糕。 會更新視頻所屬播放列表的信息,因此您必須對所有文件執行此操作...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.