What are the advantages of storing image names instead of actual images in a database?
Storing image names instead of actual images in a database can help improve database performance and reduce storage space. By storing just the image names, the actual images can be stored in a separate location (such as a server or cloud storage) and retrieved when needed. This can also make it easier to manage and update images without having to modify the database.
// Example code snippet to store image names in a database
// Connect to database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "images";
$conn = new mysqli($servername, $username, $password, $dbname);
// Insert image name into database
$image_name = "example.jpg";
$sql = "INSERT INTO images_table (image_name) VALUES ('$image_name')";
if ($conn->query($sql) === TRUE) {
echo "Image name stored successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Close database connection
$conn->close();