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
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";
?>
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
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());
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.