Her er en simpel forklaring på, hvilke linjer der gør hvad. Hvis du gerne vil vide specifikt, hvad de enkelte dele af disse betyder, så sig venligst hvilke, så de kan forklares nærmere for dig. Eller de korrekte links pegede på.
Jeg bemærker, at du bruger W3Schools for eksempel som en næsten nøjagtig kopi og indsæt. Har du installeret MySQL på din maskine og oprettet et brugernavn og en adgangskode?
<?php
$servername = "localhost"; // This is the location of your server running MySQL
$username = "username"; // This is the username for MySQL
$password = "password"; // This is the password for MySQL
// Create connection
$conn = new mysqli($servername, $username, $password); // This is where you create a connection
// Check connection
if ($conn->connect_error) { // This checks if the connection happened
die("Connection failed: " . $conn->connect_error); // and produces an error message if not
} // otherwise we move on
// Create database
$sql = "CREATE DATABASE myDB"; // This is the SQL query which is sent to the MySQL server
if ($conn->query($sql) === TRUE) { // When the if statement begins here, it executes the query and test if it returns true
echo "Database created successfully"; // If it returns true then here is the message is returns
}
else {
echo "Error creating database: " . $conn->error; // Or if there was error with the query this is returned
}
$conn->close(); // Close the connection when it is no longer in use
?>