Hi everyone, just wanted to know what type should i use in mysql database to store the urls (for linking purposes) of videos(from youtube,vimeo) and slides (from slideshare)...i just want to store the urls not the whole video..for tht i wud use directory/ file functions.. please help... helpful comments will be appreciated :)

Dani AI

Generated

Quick, practical guidance that builds on ’s question and the replies from and .

For third‑party links (YouTube, Vimeo, Slideshare) there are two good patterns: store the full URL, or store a small set of structured fields (provider + provider_id) and build/embed the URL when needed. The URI spec defines syntax but does not set a strict maximum length; browser and server implementations impose practical limits (Internet Explorer historically ~2083 chars), so plan for variability. (rfc-editor.org)

Which column type to use?

  • If you can bound the length (typical external video URLs are short), a well‑chosen VARCHAR is efficient and indexable.
  • If you expect very long or unpredictable URIs, TEXT avoids row‑size constraints but behaves differently for defaults and indexing. Read the MySQL rules for VARCHAR vs TEXT and the effective max length (it depends on character set and row size). (dev.mysql.com)

Indexing and charset notes

  • If you must search or enforce uniqueness on the URL, prefer splitting out provider and resource id (small, indexable columns) rather than indexing a very long URL. InnoDB has index key prefix limits (767 bytes by default, up to 3072 bytes with modern settings), and utf8mb4 uses up to 4 bytes/char—so long indexed VARCHARs can fail or be inefficient. (dev.mysql.com)

Validation, normalization and security

  • Always validate and canonicalize server‑side (e.g., PHP filter_var with FILTER_VALIDATE_URL), whitelist allowed schemes (http/https) and domains for embeds, and use prepared statements to store values safely to avoid SQL injection. When rendering user-supplied URLs, escape attribute contexts and follow OWASP guidance for URL handling to avoid XSS/SSRF. Example table + PHP flow:
CREATE TABLE media (
  id INT AUTO_INCREMENT PRIMARY KEY,
  provider VARCHAR(20) NOT NULL,
  media_id VARCHAR(64) NOT NULL,
  url VARCHAR(2048) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX(provider, media_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
$url = trim($_POST['url']);
if (!filter_var($url, FILTER_VALIDATE_URL)) { /* reject */ }
$stmt = $pdo->prepare('INSERT INTO media (provider, media_id, url) VALUES (:p,:id,:u)');
$stmt->execute([':p'=>$provider,':id'=>$mediaId,':u'=>$url]);

Cite the PHP and security references when implementing validation and prepared statements. (php.net)

Summary: for most YouTube/Vimeo/Slideshare links storing a VARCHAR sized for a few KB (or better, provider+id columns) plus server validation and prepared statements hits the right balance of safety, portability and performance.

Recommended Answers

All 5 Replies

A VARCHAR[255] field should allow sufficient space for the URLs.

thnakyou so much
any other thing that should be mentioned while saving these types of fields in mysql?? actually iam new to mysql n php so dont have an idea what else should be used.. tanhks in advance :)

-
I did wonder whether to suggest a longer length, but the likelihood of a URL being that long is very unlikely in my opinion.

@Rui_2009 -
My only other suggestion would be to not include the host name in the URL for files hosted on your server. This will make it easier to move between development, staging and live environments.

For Youtube, Vimeo URLs, etc, you'll obviously need the full URL.

yes i would need the full url thanks all :)

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.