-1

我有一个从 WebQuery 获取数据的 Excel 文件,我想读取数据,插入 mySQL 数据库。无法使用以下代码写入 mysql 数据库。有任何想法吗?

<?php
$db_host = "localhost";$db_user = "root";$db_pass = "";$db_name ="report";$db_table = "test";
require '/PHPExcel/Classes/PHPExcel.php';
require_once '/PHPExcel/Classes/PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load('Refreshables.xlsx');
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) 
{
$worksheetTitle     = $worksheet->getTitle();
$highestRow         = $worksheet->getHighestRow(); // e.g. 10
$highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
    $link = mysql_connect($db_host,$db_user,$db_pass);
if(!$link) die ('Could not connect to database: '.mysql_error());
mysql_select_db($db_name,$link);
    for ($row = 2; $row <= $highestRow; ++ $row) 
{
    $val=array();
    for ($col = 0; $col < $highestColumnIndex; ++ $col) 
    {
        $cell = $worksheet->getCellByColumnAndRow($col, $row);
        $val[] = $cell->getValue();
    }
        $sql = "insert into 'test' (AppName, Device_Full_Name, App_Type, Carrier, Language, Version, Status, Platform, Project_Type, Base_Device, Build_Type, Project_ID) values('".$val[0]."', '".$val[1]."', '".$val[2]."','".$val[3]."', '".$val[4]."', '".$val[5]."','".$val[6]."', '".$val[7]."', '".$val[8]."','".$val[9]."', '".$val[10]."', '".$val[11]."')";
        mysql_query($sql);
} 
}
mysql_close($link);
?>
4

1 回答 1

0

改变

$sql = "insert into 'test' (AppName,...
                    ^    ^ don't use quotes in table or column names

$sql = "insert into `test` (AppName,...

甚至没有反勾号

$sql = "insert into test (AppName,...
于 2013-05-06T07:52:16.123 回答