If you consider the following table
table_A (id (PK), value1, value2)
If I want to insert a data set, for example: (1,5), (1,3), (3,5)
I could fulfill the request, for example:
INSERT INTO table_A (value1, value2) VALUES (1,5), (1,3), (3,5)
which will work. However, they tell me that prepared statements will be better. Looking at the prepared statements, I think I needed to do something like this.
$stmt = $dbh->prepare("INSERT INTO table_A (value1, value2) VALUES (?, ?)"); $stmt->bindParam(1, $value1); $stmt->bindParam(2, $value2); //for each set of values $value1 = 1; $value2 = 5; $stmt->execute();
My question is, how can a prepared statement be better (in terms of performance) than the first method? One is one request, the other is multiple executions of the same request. Is the first query compiled into three separate queries or something else?