0

我想创建一个记录对数据库所做更改的 .txt 日志文件。基本上每当有人添加记录时,我希望日志记录类似“在 2013 年 10 月 3 日 12:21:43 史密斯,乔添加了以下约会:......一些约会细节......”

我有一个functions.php文件,它具有以下功能(哦,暂时请耐心等待mysql vs mysqli - 该更新正在进行中,但尚未发生):

function getCalendarChange($id) {
require("db.php"); //database connection
    $sql = "SELECT calendar_event.consultant_id, calendar_event.client_id, calendar_event.event_id, calendar_event.billing_id, calendar_event.dates_id, consultant.f_name, consultant.l_name, client.client_name, event_type.event_type, billing_status.billing_type, dates.date FROM calendar_event
    INNER JOIN consultant ON calendar_event.consultant_id = consultant.consultant_id
    INNER JOIN client ON calendar_event.client_id = client.client_id
    INNER JOIN event_type ON calendar_event.event_id = event_type.event_id
    INNER JOIN billing_status ON calendar_event.billing_id = billing_status.billing_id
    INNER JOIN dates ON calendar_event.dates_id = dates.date_id
    WHERE calendar_event_id = '$id'";
    $result = mysql_query($sql,$connection) or die (mysql_error());
    $results = mysql_fetch_array($result);

    $consultant = $results['l_name'] . ", " . $results['f_name'];
    $client = $results['client_name'];
    $event = $results['event_type'];
    $billing = $results['billing_type'];
    $eventdate = $results['date'];

    echo $consultant . " " . $client . " " . $event . " " . $billing . " " . $eventdate;
}

在处理表单以插入新记录的页面中,我有以下内容:

include("functions.php");
$add_appt_query = "INSERT INTO calendar_event (calendar_event_id, consultant_id, client_id, event_id, billing_id, dates_id) VALUES (NULL, '$addee', '$addclient', '$addevent', '$addbilling', '$dt')";
$add_appt_result = mysql_query($add_appt_query,$connection) or die(mysql_error());
$chngid = mysql_insert_id(); //gets the last auto increment id - yes this is set to be an auto increment column
$new_appointment = "<p>Appointments added successfully.</p>"; //everything works up to here - the appointment is added to the db as expected 

// start log new appointment
$log_data = "On " . $log_datetime . " " . $ee_log_name . " added the following appointment: "; //$log_datetime and $ee_log_name are defined elsewhere, but work correctly
$log_data .= getCalendarChange($chngid) . "\n";
$log_data .= file_get_contents('mod.txt');
file_put_contents('mod.txt', $log_data); //done this way so the newest change is at the beginning of the file not the end
// end log new appointment

最终在 mod.txt 中的内容类似于“在 2013 年 10 月 3 日 12:21:43 史密斯,乔添加了以下约会:”它添加了我想要的所有内容,除了来自getCalendarChange().

我试图删除 getCalendarChange 和只是 echo $chngid,它会产生 id# 正如您所期望的那样。

getCalendarChange(100)在functions.php 文件中使用静态数字调用了getCalendarChange 函数,它显示了该特定事件的正确信息。

我已经换成$chngidgetCalendarChange($chngid)getCalendarChange(100)还是不行。(是的,有一条 id 为 100 的记录)。

为什么getCalendarChange($chngid)在 functions.php 文件之外不起作用?

4

0 回答 0