How does the method differ for different database systems like MySQL, PostgreSQL, and Oracle?

Different database systems like MySQL, PostgreSQL, and Oracle have their own unique syntax and functions for executing queries. When writing PHP code that interacts with these databases, it is important to use the correct syntax and functions for each database system to ensure compatibility and proper execution of queries.

// Example of connecting to a MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

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

// Example of executing a query in MySQL
$sql = "SELECT * FROM table";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"] . " - Name: " . $row["name"] . "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();