I have an import books function to insert more than 5000 rows at once, I did some research and did this one but some other places I saw a different kind of methods to insert without looping and execute this. is my code got any trouble with the performance of app
public function importBooks($data, $no_of_rows)
{
try {
// Start transaction
$this->db->beginTransaction();
// Init query
$this->db->query('INSERT INTO books_pre (title, author, publication, container, tmp_no, created_by, created_at) VALUES (:title, :author, :publication, :container, :tmp_no, :created_by, now())');
for ($i=2; $i<=$no_of_rows; $i++) {
// Bind values
$this->db->bind(':title', $data[$i]['B']);
$this->db->bind(':author', $data[$i]['C']);
$this->db->bind(':publication', $data[$i]['D']);
$this->db->bind(':container', $data[$i]['E']);
$this->db->bind(':tmp_no', $data[$i]['A']);
$this->db->bind(':created_by', $_SESSION['user_id']);
// Execute query
if (!$this->db->execute()) {
return false;
}
}
// Commit data
$this->db->commitTransaction();
} catch (Exception $e) {
$this->db->cancelTransaction();
echo "Failed: " . $e->getMessage();
}
}