-1

有没有办法为codeigniter中的不同表在同一函数中编写插入查询和更新查询。

意思是说我想更新一个表,并且在同一个查询中我想在其他表中插入响应时间,请告诉我方法。

提前谢谢

4

4 回答 4

2

您可以这样做:
在执行更新查询之前记录时间。说是time1
然后找到执行查询后的时间差current system time - time1并将其插入所需的表中。

编辑
添加示例代码:

<?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";
?>
于 2013-03-08T06:34:21.237 回答
0

尝试这个:

$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);
于 2013-03-08T07:35:09.523 回答
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);

}

我希望它有帮助

于 2013-03-08T06:59:33.057 回答
0

据我所知,您不能用一个查询更新多个表。您可以运行第二个查询并使用 MySQL 函数 'NOW()' 将当前时间插入到字段中。

INSERT INTO 表(id​​、数据、已发布)VALUES(0, '12345', NOW());

于 2013-03-08T07:01:34.563 回答