How can a link with a variable be properly stored in a database using PHP?

When storing a link with a variable in a database using PHP, it's important to properly sanitize the variable to prevent SQL injection attacks. One common method is to use prepared statements with parameterized queries to securely insert the variable into the database. This ensures that the variable is treated as data rather than executable SQL code.

// Assume $link is the variable containing the link
// Assume $pdo is your database connection

$stmt = $pdo->prepare("INSERT INTO links_table (link_column) VALUES (:link)");
$stmt->bindParam(':link', $link, PDO::PARAM_STR);
$stmt->execute();