I try to Insert Multiple Records in my DB but give error when I use the third INSERT Statement
I need Help Plz.
I’ve looked through all the other StackOverflow (and google) posts with the same problem, but none seemed to address my problem.
I am using PDO and PHP.
My code:
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// begin the transaction
$conn->beginTransaction();
// our SQL statements
$conn->exec("INSERT INTO emp (emp_name, emp_address, emp_salary, join_date)
VALUES ('John', 'Doe', '5000', '30.03.2022')");
$conn->exec("INSERT INTO emp (emp_name, emp_address, emp_salary, join_date)
VALUES ('Johny', 'Doeo', '50000', '30.05.2022')");
$conn->exec("INSERT INTO emp (femp_name, emp_address, emp_salary, join_date)
VALUES (Johnn', 'Doeoo', '500000', '30.06.2022)");
// commit the transaction
$conn->commit();
echo "New records created successfully";
} catch(PDOException $e) {
// roll back the transaction if something failed
$conn->rollback();
echo "Error: " . $e->getMessage();
}
$conn = null;
?>