What are the recommended steps for transitioning from using mysql_ functions to mysqli or PDO in PHP scripts that handle CSV file uploads for database insertion?

When transitioning from using mysql_ functions to mysqli or PDO in PHP scripts that handle CSV file uploads for database insertion, the recommended steps include updating the connection method to mysqli or PDO, modifying the query execution process to use prepared statements to prevent SQL injection, and adjusting any other mysql_ function calls to their mysqli or PDO equivalents.

// Connect to the database using mysqli
$mysqli = new mysqli('localhost', 'username', 'password', 'database');

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

// Open the CSV file for reading
$csvFile = fopen('file.csv', 'r');

// Prepare a statement for inserting data into the database
$stmt = $mysqli->prepare("INSERT INTO table_name (column1, column2) VALUES (?, ?)");

// Bind parameters for the prepared statement
$stmt->bind_param('ss', $column1, $column2);

// Read and insert data from the CSV file
while (($data = fgetcsv($csvFile)) !== false) {
    $column1 = $data[0];
    $column2 = $data[1];
    $stmt->execute();
}

// Close the prepared statement and CSV file
$stmt->close();
fclose($csvFile);

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