-
-
Save ismkdc/bed68d5019399d4a8f4d0ab5c7cd5be0 to your computer and use it in GitHub Desktop.
servephp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Function to fetch data from MySQL database | |
function fetchDataFromDatabase() { | |
// Replace these with your MySQL database credentials | |
$servername = "your_mysql_host"; | |
$username = "your_mysql_username"; | |
$password = "your_mysql_password"; | |
$dbname = "your_mysql_database"; | |
// Create connection | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
// Check connection | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
// Query to fetch data | |
$sql = "SELECT * FROM your_table"; | |
$result = $conn->query($sql); | |
// Fetch data and return | |
$data = array(); | |
if ($result->num_rows > 0) { | |
while ($row = $result->fetch_assoc()) { | |
$data[] = $row; | |
} | |
} | |
// Close connection | |
$conn->close(); | |
return $data; | |
} | |
// Function to generate HTML from data | |
function generateHTML($data) { | |
$html = "<html><head><title>Your Data</title></head><body><h1>Your Data</h1><ul>"; | |
foreach ($data as $row) { | |
$html .= "<li>{$row['name']}: {$row['value']}</li>"; | |
} | |
$html .= "</ul></body></html>"; | |
return $html; | |
} | |
// Function to save HTML to a static file | |
function saveHTMLToFile($html) { | |
$filename = "static_data.html"; | |
file_put_contents($filename, $html); | |
} | |
// Fetch data from the database | |
$data = fetchDataFromDatabase(); | |
// Generate HTML | |
$html = generateHTML($data); | |
// Save HTML to a static file | |
saveHTMLToFile($html); | |
// Serve the static HTML file | |
echo $html; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment