How can one ensure compatibility between PHP 4.3.x and PHP 5.x when using MySQL?

To ensure compatibility between PHP 4.3.x and PHP 5.x when using MySQL, you can use the MySQLi extension which is available in both PHP versions. This extension provides an object-oriented interface for interacting with MySQL databases and is compatible with both PHP 4.3.x and PHP 5.x.

// Create a new MySQLi object
$mysqli = new mysqli('localhost', 'username', 'password', 'database');

// Check connection
if ($mysqli->connect_error) {
    die('Connection failed: ' . $mysqli->connect_error);
}

// Perform a query
$result = $mysqli->query('SELECT * FROM table');

// Fetch results
while ($row = $result->fetch_assoc()) {
    // Do something with the data
}

// Close connection
$mysqli->close();