从mdb文件导入数据到mysql数据库无法上传数据

时间:2014-04-25 08:32:31

标签: php mysql ms-access

我使用PHP代码将数据从MDB文件上传或插入MySQL数据库。我想将我的表值插入到MySQL数据库中。但数据没有插入到MySQL数据库中。这段代码显示我没有错误。这是我的代码。请帮助我尝试了网上的每一个解决方案。

 <?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $dbname = 'payroll_system';

    //mysql
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    mysql_select_db($dbname);
    $sql = "SELECT * FROM attendance";
    $result = mysql_query($sql);

    //mdb
    $conn2 = new COM("ADODB.Connection") or die("Cannot start ADO"); 
    $conn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\\xampp\\htdocs\\payroll\\eTimeTrackLite1.mdb");
    $rs = $conn2->Execute("SELECT * FROM AttendanceLogs");

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
                    {

                        $column1=$row["AttendanceLogId"];$column2=$row["AttendanceDate"];$column3=$row["EmployeeId"];$column4=$row["InTime"];
                        $column6=$row["OutTime"];$column8=$row["Duration"];
                        echo "hello";
                        echo $column1;echo $column2;echo $column3;echo $column4;
                        $rs->MoveFirst();
                        while (!$rs->EOF) 
                        {
                        $attendance_id = $rs->Fields("AttendanceLogId");
                        $attendance_date = $rs->Fields("AttendanceDate");
                        $emp_id = $rs->Fields("EmployeeId");
                        $in_time = $rs->Fields("InTime");
                        $out_time = $rs->Fields("OutTime");
                        $duration = $rs->Fields("Duration");
                        mysql_query("UPDATE attendance SET AttendanceLogId = '$attendance_id', AttendanceDate='$attendance_date', EmployeeId='$emp_id',InTime='$in_time',OutTime='$out_time',Duration='$duration'  '"); ?>

                            <?php


                        $rs->MoveNext();
                        }

                    }               
        ?>
        </table> <?php
       mysql_free_result($result);
        $rs->Close();
        $conn2->Close();
        $rs = null;
        $conn2 = null;



    ?>

1 个答案:

答案 0 :(得分:0)

您需要INSERT每个记录数据而不是UPDATE。重写以下行:

mysql_query("UPDATE attendance SET AttendanceLogId = '$attendance_id', AttendanceDate='$attendance_date', EmployeeId='$emp_id',InTime='$in_time',OutTime='$out_time',Duration='$duration'  '");