I haven't used MySQL for a long time and I forgot a lot, I'm developing a script that saves a list of URL's but I have a lot of doubts..

should I use varchar or text? (what is the difference)
Which characters should I escape?
what should be the length?
should I encrypt the URL's?

text data type is for very long texts. MySQL doesn't allow for indexes of more than 1024 characters, so you couldn't index a full length text field, but you can index the whole of a varchar field.
URLs can be more than 1.000 chars long, though. So if you plan to store URLs that long, you cannot index them in full length. Then you will need a hash value field with the MD5 or a similar hash value which can be indexed, and you cannot have a unique index for URLs that long.
Therefore chose varchar if you can guarantee that your URLs will have less than 256 chars, and text otherwise.
Set up the database and all connections in UTF-8 and don't worry any more about escaping and encoding.
What for would you encrypt URLs?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.