You are on page 1of 2

An example of how you might retrieve and display a date from a MySQL database using PHP:

<?php

// Replace these with your actual database connection details

$servername = "localhost";

$username = "your_username";

$password = "your_password";

$dbname = "your_database";

// Create connection

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

// Check connection

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

// SQL query to retrieve date from the database

$sql = "SELECT your_date_column FROM your_table_name";

$result = $conn->query($sql);

if ($result->num_rows > 0) {

// Output data of each row


while ($row = $result->fetch_assoc()) {

echo "Date: " . $row["your_date_column"] . "<br>";

} else {

echo "0 results";

$conn->close();

?>

Replace the placeholders (your_username, your_password, your_database, your_table_name,


your_date_column) with your actual database information. This PHP code connects to a MySQL
database, executes a SELECT query to retrieve the date column's value, and then displays it. Adjust the
echo statement to format the date according to your needs.

You might also like