在MySQL数据库中存储歌词 [英] Storing Lyrics in a MySQL database

查看:529
本文介绍了在MySQL数据库中存储歌词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在mysql数据库中存储音乐 Lyrics的最佳方法是什么。以及用于什么的设置。另外,我希望表格存储折线。

I wanted to know what is the best way of storing music "Lyrics" in a mysql database. and what are the setting used for that. Also, i would like the table to store the break lines.

我正在考虑使用 |指示新行并使用php替换字符串。

I was thinking about using "|" to indicate a new line and using php to replace string.

我不知道从哪里开始,或者使用什么作为参数(varchar,int(我知道这是

I have no idea where to start, or what to use for the parameters (varchar, int (i know it's not going to be int), etc.)

当前,我的曲目表是这样布置的

Currently, I have my tracks table laid out like this

table tracks
----
id (int, 10, primary key)
albumid (foreign key to albums table)
name (varchar, 50)
override_artist (overrides album artist if not null)
playtime (int, 5)
lyric (??????)

任何想法都很棒。

推荐答案

您的歌词列应为 TEXT 类型,并且您可能应该将其存储在单独的MyISAM表中,该表的键为 tracks 表,如果您的 tracks 表使用InnoDB引擎(默认情况下新安装)。这将使您能够在TEXT列上进行全文搜索:

Your lyric column should be the TEXT type, and you should probably store it in a separate MyISAM table keyed to the tracks table if your tracks table uses the InnoDB engine (which new installs do by default). This will enable you to do full text searches over the TEXT column:

表格歌词:

CREATE TABLE lyric (
  lyricid INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  /* foreign key to tracks.id */
  trackid INT,
  lyric TEXT,
  FOREIGN KEY (trackid) REFERENCES tracks (id)
) ENGINE=MyISAM;

您可以简单地将换行符存储为歌词中的普通旧换行符。您无需在数据库中替换它们。相反,在HTML输出中,您可以将它们转换为< br /> (在PHP中,这是通过 nl2br())。换句话说,如果您在具有换行符的数据库中输入文本,请不要对其进行任何特殊处理。他们会很好的。

You can simply store the linebreaks in the lyrics as plain old line breaks. You don't need to replace them in the database. Instead, in your output to HTML, you would convert them to <br /> (in PHP, that's done with nl2br()). In other words, if you enter text into the database that has linebreaks, don't treat them specially at all. They'll work fine.

这篇关于在MySQL数据库中存储歌词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆