我是 php 新手。我需要在 php 中将 excel 详细信息导入 MySQL 数据库。我下载了 2 个文件reader.php
&oleread.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>