Create SQL file after submitting form in PHP Codeigniter

I have a data entry project, an online application using PHP Codeigniter. There are over 150 questions in my project, with about 400 users.

I was worried that with so many questions and many users, especially I just use a simple method to insert data into the database. I am using a form action and submit with POST.

I think that converting the data I posted earlier to a SQL file and uploading it to the server will be better. But I don't know about this method. Or maybe I can use a different method or way?

Need help, sorry for my bad english and thank you so much.

+3


source to share


1 answer


To maintain database integrity, you must use transactions (if you are inserting / updating data from multiple tables in a single query).

$db->beginTransaction();
try 
{
    // insert data to first table
    // insert data to second table
    ...
    // insert data to last table

    $db->commit();                 
}
catch (Exception $e)
{
    $db->rollBack();
}

      

This is an example using Zend, but the idea is similar to CodeIgniter. Perhaps the implementation (method names) is different.



CodeIgniter example:

$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
$this->db->trans_complete(); 

      

You will find more information about CodeIgniter operations here: http://ellislab.com/codeigniter/user-guide/database/transactions.html

+1


source







All Articles