繁体   English   中英

在php中将Excel文件导入MYSQL时发生错误

[英]Error occurs while importing excel file into MYSQL in php

我是php新手。 我需要将excel详细信息导入php中的MySQL数据库。 我下载了2个文件reader.phpoleread.php并将其保存在wamp/www/folder 当我执行以下代码时,服务器抛出错误,例如

文件名samp.xls不可读

提供解决方案以解决此问题。 我的代码是:

<html>
  <head>
  <title>Save Excel file details to the database</title>
  </head>
  <body>
    <?php
        include 'db_connection.php';
        include 'reader.php';
        $excel = new Spreadsheet_Excel_Reader();
    ?>
        <table border="1">
        <?php
            $excel->read('samp.xls');
            $x=2;
            while($x<=$excel->sheets[0]['numRows']) {
                $id = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][1] : '';
                $name = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][2] : '';
                // Save details
                $sql_insert="INSERT INTO students (sid,name) VALUES ('$id','$name')";
                $result_insert = mysql_query($sql_insert) or die(mysql_error());
              $x++;
            }
        ?>
    </table>
  </body>
</html>

为什么不将其直接导入phpmyadmin? 点击这里

文件名samp.xls不可读

首先想到的是您的php服务器无法读取您的excel文件。

WAMPWindows上 ,因此右键单击您的excel文件,然后将read属性添加到Everyone

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM