What are the best practices for optimizing performance when sending multiple queries to a database in PHP?

When sending multiple queries to a database in PHP, it is best to use prepared statements to prevent SQL injection attacks and improve performance. Additionally, you can optimize performance by batching queries together using transactions, reducing the number of round trips to the database.

// Establish a database connection
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

// Begin a transaction
$pdo->beginTransaction();

// Prepare and execute multiple queries
$stmt1 = $pdo->prepare("INSERT INTO table_name (column1, column2) VALUES (:value1, :value2)");
$stmt2 = $pdo->prepare("UPDATE table_name SET column1 = :value1 WHERE column2 = :value2");

$stmt1->execute(array(':value1' => 'data1', ':value2' => 'data2'));
$stmt2->execute(array(':value1' => 'new_data', ':value2' => 'data2'));

// Commit the transaction
$pdo->commit();