How can PHP be used to handle CSV data and store it in a database table efficiently?

To handle CSV data efficiently in PHP and store it in a database table, you can use the built-in functions like `fgetcsv()` to read the CSV file line by line and `PDO` to insert the data into the database table. By using prepared statements, you can efficiently insert the data into the database without the risk of SQL injection.

<?php
// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=your_database', 'username', 'password');

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

// Loop through each row in the CSV file
while (($data = fgetcsv($handle)) !== false) {
    // Prepare the SQL statement
    $stmt = $pdo->prepare("INSERT INTO your_table (column1, column2, column3) VALUES (?, ?, ?)");
    
    // Bind the CSV data to the prepared statement
    $stmt->bindParam(1, $data[0]);
    $stmt->bindParam(2, $data[1]);
    $stmt->bindParam(3, $data[2]);
    
    // Execute the statement
    $stmt->execute();
}

// Close the CSV file and database connection
fclose($handle);
$pdo = null;
?>