-1

Is there any way to write a insert query and update query in same function for different tables in codeigniter.

Mean to say i want to update a table and in same query i want to insert a response time in other table please show me way.

Advance thanks

Sundas Subhani
  • 23
  • 2
  • 10

4 Answers4

2

You can do this:
Log the time before executing the update query. say it is time1.
Then find the difference of the time between current system time - time1 after executing the query and insert it into desired table.

EDIT
Adding sample code:

<?php
$time_start = microtime(true);

//Your query goes here

$time_end = microtime(true);
$time = $time_end - $time_start;

echo "Execution time taken  $time seconds\n";
?>
Anubhab
  • 1,736
  • 2
  • 18
  • 28
  • for more time related info see [this](http://stackoverflow.com/questions/3656713/how-to-get-current-time-in-milliseconds-in-php) – Anubhab Mar 08 '13 at 06:40
0
public function insertUpdate() {
  $data = array(
        'tableindex'=>'datayouwanttoinsert',

        );
  $data1 = array(
       'tableindex'=>'datayouwanttoupdate',
      );
     $this->db->insert('databasename.dbo.tablename',$data);
     $this->db->update('databasename.dbo.tablename',$data1);

}

i hope it helps

jalborres
  • 107
  • 6
0

As far as I'm aware, you can't update multiple tables with one query. You can run a second query and use the MySQL function 'NOW()' to insert the current time into a field.

INSERT INTO table (id, data, posted) VALUES(0, '12345', NOW());

splash21
  • 799
  • 4
  • 10
0

Try this:

$start_time = microtime(true);
$this->db->insert('tablename1',$data);
$end_time = microtime(true);

$response_time = $time_end - $time_start;
$arrdata=array();

$arrdata['response_time']=$response_time;
 $this->db->where('id', $id);//if u have any id
$this->db->update('tablename2',$arrdata);
Rahul Chipad
  • 2,373
  • 17
  • 20