beben
beben

Reputation: 55

Create SQL file after submit form in PHP Codeigniter

I have a data entry project, online web applications using PHP Codeigniter. There are more than 150 questions in my project, with user about 400.

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

I think, with convert the datas that I have submitted before to SQL file and upload it to server, will be better. But I don't know about that method. Or, maybe I can use other method or way ??

Need help, Sorry For My Poor english, And Thank You So Much.

Upvotes: 3

Views: 561

Answers (1)

Evaldas Dzimanavicius
Evaldas Dzimanavicius

Reputation: 645

To keep database in consistent state you should be using transactions (if you are inserting/updating data from multiple tables in one request).

$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 the same with CodeIgniter. Maybe implementation (method names) are 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(); 

Here you find more info about transactions with CodeIgniter: http://ellislab.com/codeigniter/user-guide/database/transactions.html

Upvotes: 1

Related Questions