请教PHP导入Excel到MySQL的问题
<br /><?php<br />require_once 'reader.php';<br /><br />$data = new Spreadsheet_Excel_Reader();<br /> <br />$data->setOutputEncoding('gbk');<br /><br />$data->read('in.xls');<br />@ $db = mysql_connect('localhost', 'root', '123456') or<br />die("Could not connect to database.");<br />mysql_query("set names 'gbk'");<br />mysql_select_db('test1'); <br />error_reporting(E_ALL ^ E_NOTICE);<br /><br /><br />for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {<br /> <br /><br /> $a = $data->sheets[0]['cells'][$i][1];//取得第一列的数据<br /> $b = $data->sheets[0]['cells'][$i][2];//取得第二列的数据<br /> $c = $data->sheets[0]['cells'][$i][3];//取得第三列的数据<br /> $d = $data->sheets[0]['cells'][$i][4];//取得第四列的数据<br /> $e = $data->sheets[0]['cells'][$i][5];//取得第五列的数据<br /> $f = $data->sheets[0]['cells'][$i][6];//取得第六列的数据<br /> $g = $data->sheets[0]['cells'][$i][7];//取得第七列的数据<br /><br /> <br /> $sql = "INSERT INTO appexp (account,appinfo,price,result,income,pay,date) VALUES('$a','$b','$c','$d','$e','$f','$g')";<br /> echo $sql.'<br />';<br /> $res = mysql_query($sql) or die ("错误:$sql");<br />} <br /> ?> <br />
<br><?php <br /><br>require_once 'Excel/reader.php';<br><br>$data = new Spreadsheet_Excel_Reader();<br><br>if($_FILES){<br><br> $check = substr($_FILES["file"]["name"],strrpos($_FILES["file"]["name"],".")+1); <br><br> if ( $check == "xls" <br><font color="#FF8000">------解决方案--------------------</font><br> $check == "xlsx")<br> {<br> move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);<br> }<br> else<br> {<br> exit('no');<br> }<br><br>$data->setOutputEncoding('UTF-8');<br><br>$data->read("upload/" . $_FILES["file"]["name"]);<br><br>error_reporting(E_ALL ^ E_NOTICE);<br><br>$db_host = 'localhost'; //edit_config<br>$db_user = 'root';<br>$db_password = 'root';<br>$db_port = 3306;<br>$db_name = 'test';<br><br>$con = mysql_connect($db_host,$db_user,$db_password);<br>if (!$con)<br> {<br> die('Could not connect: ' . mysql_error());<br> }<br><br>$db_selected = mysql_select_db($db_name, $con);<br><br>if (!$db_selected)<br> {<br> die ("Can\'t use test_db : " . mysql_error());<br> }<br><br>//删除已存在表<br><div class="clear"> </div>