如何在php查询之前启用日志

时间:2019-02-15 18:15:44

标签: php mysql jenkins

我正在尝试'在php查询之前添加日志'的方法;努力实现在mySQL数据库更新后打印“时间戳”的功能。

我的查询如下。

 require_once('include/connect.php');

  $q = $_GET['q'];
  //echo $q;
  //$plan=substr($q,0,4);
  //$spec=substr($q,4);
  list($plan, $ptype, $spec) = explode('_', $q);
  //echo  $plan . ", " . $spec;
  //$query="SELECT vphp.tbl_provider_types.`TYPE` from coolDB.tbl_provider_types where vphp.tbl_provider_types.".$q." = 'Y';";
  $query= "SELECT tbl_sourcespecheader.specID, coolDB.tbl_sourcespecheader.Specialty_Header from vphp.tbl_provider_types left join coolDB.tbl_sourcespecheader on coolDB.tbl_provider_types.ID = coolDB.tbl_sourcespecheader.TypeID where coolDB.tbl_provider_types.ID = " . $spec . " and coolDB.tbl_sourcespecheader." . $plan . " = 'Y';";

  $result = mysqli_query($connection, $query);

  //Populate result in HTML which will be returned via AJAX
  echo "<h4>Please select from these " . $ptype . " specialties:</h4>";
  echo "<select id='type' multiple='' name='specialty'><option selected="selected" value="nospec"></option>";
  while($row = mysqli_fetch_array($result))
    {
      echo "<option value='" . $row['specID'] . "'><a href='#'  id='" . $row['specID'] . "' onclick='getSelected(this.id);return false'  style='text-decoration: none'>" . $row['Specialty_Header'] . "</a></option>";
    }
  echo "</select>";

  //Close database connection
  mysqli_close($connection); 

1 个答案:

答案 0 :(得分:1)

更好地使用触发器。您需要创建日志表才能插入所需的所有数据。以下是示例。

DELIMITER $$
CREATE TRIGGER before_employee_update 
    BEFORE UPDATE ON employees
    FOR EACH ROW 
BEGIN
    INSERT INTO employees_audit
        SET action = 'update',
        employeeNumber = OLD.employeeNumber,
        lastname = OLD.lastname,
       changedat = NOW(); 
END$$
DELIMITER ;

如果您使用的是phpMyadmin。转到该行并找到触发器菜单。在那里您可以创建触发器。