How can links be extracted from a database in PHP?

To extract links from a database in PHP, you can use SQL queries to retrieve the link data from the database table where the links are stored. You can then loop through the results and output the links as needed in your PHP code.

// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// SQL query to select links from the database
$sql = "SELECT link FROM links_table";
$result = $conn->query($sql);

// Output links
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "<a href='" . $row["link"] . "'>" . $row["link"] . "</a><br>";
    }
} else {
    echo "0 results";
}

// Close connection
$conn->close();