What kind of data do you use to store Uris in the database?

Asked

Viewed 624 times

5

What kind of data to use to store Uris in the database, taking into account an indeterminate or very large URI length?

  • 3

    Urls that pass 2K do not have much guarantee that they will work, except in applications specifically written thinking about it. RFC recommences at least 8K support, but until the IE10, it was not possible to pass the 2K in the address bar. More details here: http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers - I would suggest thinking about what your application will actually need, limit the value and document correctly.

  • 1

    Related: http://answall.com/q/43224/101

  • 1

    A good doubt Vinicius +1

  • This answers your question? Store data in the database using PDO::commit

  • @Gonçalo the questions have no relation, could check if indicated the right link?

1 answer

7


If you consider that Urls do not usually exceed 2K in size and that the VARCHAR in Mysql supports up to 65535 characters (the line also has this limit, so in practice it has to be a little smaller. This gives with leftovers.

In theory a URL can be larger, so if you want to guarantee it would be interesting to use a MEDIUMTEXT (16MB) or LONGTEXT (4GB). But I think a big nonsense, I would go to VARCHAR even, until it’s proven that you need something bigger.

Obviously I discard any type that is not text, at least in Mysql.

More details on What types of data exist in Mysql for text?.

The question originally spoke in URL and then changed to URI. It is still worth the same. It is more likely to pass the size of a URI VARCHAR, but depending on how the URI is composed the best solution would be another.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.