How can PHP be used to handle INSERT queries for individual data records efficiently?

To handle INSERT queries for individual data records efficiently in PHP, you can use prepared statements with parameterized queries. This helps prevent SQL injection attacks and improves performance by allowing the database to optimize query execution.

// Establish a connection to the database
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');

// Prepare the INSERT statement with placeholders
$stmt = $pdo->prepare("INSERT INTO table_name (column1, column2) VALUES (:value1, :value2)");

// Bind the parameter values to the placeholders
$stmt->bindParam(':value1', $value1);
$stmt->bindParam(':value2', $value2);

// Set the parameter values
$value1 = 'data1';
$value2 = 'data2';

// Execute the prepared statement
$stmt->execute();