开发者

Data Type for storing URLs

开发者 https://www.devze.com 2023-01-09 17:52 出处:网络
What is the best data type to store URLs? I need to 开发者_开发技巧save file system paths for pictures in a database.URLs are strings and will be of variable lenghts.

What is the best data type to store URLs?

I need to 开发者_开发技巧save file system paths for pictures in a database.


URLs are strings and will be of variable lenghts.

If your database system supports this, use VARCHAR.


VARCHAR is quite enough.

CHAR should be used for storing fix length character strings. String values will be space/blank padded before stored on disk. If this type is used to store varibale length strings, it will waste a lot of disk space.


VARCHAR2(4000) is sufficient for your needs


We tend to save them as urlencoded VARCHARs. (Since our URLs are coming to the database from a server, we encode them using PHP's urlencode and then decode them when we retrieve them with urldecode.) Don't think there's really much else that needs done - you could probably just store them as unencoded VARCHARs.


varchar. Choose a suitable max length based on your domain knowledge.

0

精彩评论

暂无评论...
验证码 换一张
取 消