 |
ถามปัญหาเรื่อง import csv mysql โดย php upload แล้วข้อมูลไม่ครบ |
|
 |
|
|
 |
 |
|
จะนำไฟล์ .csv มาอัพโหลดผ่านหน้าเว็บ ให้ import ลงใน database แต่ติดปัญหาที่ Import ไปแล้วแถวไม่ครบ มันได้ 1683 แถว แต่ถ้านำไฟล์ไปอัพใน MySQL เลย มันจะได้ 1692 ครบเลย ไม่ทราบว่าจะแก้ไขยังไง
File : file.csv
Code (SQL)
CREATE TABLE `mydata` (
`b1` text collate utf8_unicode_ci NOT NULL,
`b2` text collate utf8_unicode_ci NOT NULL,
`b3` text collate utf8_unicode_ci NOT NULL,
`EndtoEnd` text collate utf8_unicode_ci NOT NULL,
`Calcu` text collate utf8_unicode_ci NOT NULL,
`CATBFKT` text collate utf8_unicode_ci NOT NULL,
`TT` text collate utf8_unicode_ci NOT NULL,
`Ticket` text collate utf8_unicode_ci NOT NULL,
`AMO` text collate utf8_unicode_ci NOT NULL,
`Zone` text collate utf8_unicode_ci NOT NULL,
`ActionTeam` text collate utf8_unicode_ci NOT NULL,
`SLA` text collate utf8_unicode_ci NOT NULL,
`b5` text collate utf8_unicode_ci NOT NULL,
`Starts` text collate utf8_unicode_ci NOT NULL,
`Restores` text collate utf8_unicode_ci NOT NULL,
`Times` text collate utf8_unicode_ci NOT NULL,
`Delay` text collate utf8_unicode_ci NOT NULL,
`Total` text collate utf8_unicode_ci NOT NULL,
`Site` text collate utf8_unicode_ci NOT NULL,
`SitexTime` text collate utf8_unicode_ci NOT NULL,
`b6` text collate utf8_unicode_ci NOT NULL,
`Problem` text collate utf8_unicode_ci NOT NULL,
`Edit` text collate utf8_unicode_ci NOT NULL,
`More1` text collate utf8_unicode_ci NOT NULL,
`More2` text collate utf8_unicode_ci NOT NULL,
`Pass` text collate utf8_unicode_ci NOT NULL,
`Cause` text collate utf8_unicode_ci NOT NULL,
`Subcause` text collate utf8_unicode_ci NOT NULL,
`SANSA` text collate utf8_unicode_ci NOT NULL,
`SiteID` text collate utf8_unicode_ci NOT NULL,
`ATNT` text collate utf8_unicode_ci NOT NULL,
`TX` text collate utf8_unicode_ci NOT NULL,
`faultclearance` text collate utf8_unicode_ci NOT NULL,
`Zone2` text collate utf8_unicode_ci NOT NULL,
`OFCCATBFKT` text collate utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Code (PHP)
import.php
<html>
<head>
<title>CSV To MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form action="import.php" method="post" enctype="multipart/form-data" name="form1">
<input name="fileCSV" type="file" id="fileCSV">
<input name="btnSubmit" type="submit" id="btnSubmit" value="Submit">
</form>
</body>
</html>
<?
if(isset($_POST['btnSubmit'])){
move_uploaded_file($_FILES["fileCSV"]["tmp_name"],$_FILES["fileCSV"]["name"]); // Copy/Upload CSV
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database"); // Conect to MySQL
$objDB = mysql_select_db("data");
mysql_query("SET NAMES UTF8");
$objCSV = fopen($_FILES["fileCSV"]["name"], "r");
while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {
$strSQL = "INSERT INTO mydata ";
$strSQL .="(b1,b2,b3,EndtoEnd,Calcu,CATBFKT,TT,Ticket,AMO,Zone,ActionTeam,SLA,b5,Starts,Restores,Times,Delay,Total,Site,SitexTime,b6,Problem,Edit,More1,More2,Pass,Cause,Subcause,SANSA,SiteID,ATNT,TX,faultclearance,Zone2,OFCCATBFKT) ";
$strSQL .="VALUES ";
$strSQL .="('".$objArr[0]."',
'".$objArr[1]."',
'".$objArr[2]."',
'".$objArr[3]."',
'".$objArr[4]."',
'".$objArr[5]."',
'".$objArr[6]."',
'".$objArr[7]."',
'".$objArr[8]."',
'".$objArr[9]."',
'".$objArr[10]."',
'".$objArr[11]."',
'".$objArr[12]."',
'".$objArr[13]."',
'".$objArr[14]."',
'".$objArr[15]."',
'".$objArr[16]."',
'".$objArr[17]."',
'".$objArr[18]."',
'".$objArr[19]."',
'".$objArr[20]."',
'".$objArr[21]."',
'".$objArr[22]."',
'".$objArr[23]."',
'".$objArr[24]."',
'".$objArr[25]."',
'".$objArr[26]."',
'".$objArr[27]."',
'".$objArr[28]."',
'".$objArr[29]."',
'".$objArr[30]."',
'".$objArr[31]."',
'".$objArr[32]."',
'".$objArr[33]."',
'".$objArr[34]."') ";
$objQuery = mysql_query($strSQL);
}
fclose($objCSV);
echo "Upload & Import Done.";
}
?>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2014-06-06 16:50:10 2014-06-06 16:56:27 2014-06-06 20:25:48
|
 |
 |
 |
 |
Date :
2014-06-06 16:49:04 |
By :
nPointXer |
View :
2016 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มี error เลยเหรอครับ?
ลองเพิ่มความยาวของแต่ละแถวดู
while (($objArr = fgetcsv($objCSV, 2049, ",")) !== FALSE) {
แล้วก็ดัก error
$objQuery = mysql_query($strSQL) or die( "<br/>".mysql_error() );
|
 |
 |
 |
 |
Date :
2014-06-06 18:38:40 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
..........
|
ประวัติการแก้ไข 2014-06-09 09:33:54
 |
 |
 |
 |
Date :
2014-06-06 20:25:19 |
By :
nPointXer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ที่มันได้จำนวนแถวน้อยลงเพราะมันหยุดที่ error ครับ
ลองแสดงข้อมูล SQL แถวที่ error ดูครับ
$objQuery = mysql_query($strSQL) or die( "<br/> $strSQL <br>".mysql_error() );
|
 |
 |
 |
 |
Date :
2014-06-07 15:05:26 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันขึ้นแบบนี้ตอนกด upload ครับ ข้อมูลเข้า Database เพียงแค่ 14แถว
Quote:INSERT INTO mydata (b1,b2,b3,EndtoEnd,Calcu,CATBFKT,TT,Ticket,AMO,Zone,ActionTeam,SLA,b5,Starts,Restores,Times,Delay,Total,Site,SitexTime,b6,Problem,Edit,More1,More2,Pass,Cause,Subcause,SANSA,SiteID,ATNT,TX,faultclearance,Zone2,OFCCATBFKT) VALUES ('P', '', '2014', '3', '3', 'BFKT', 'TT20140302936', 'SKT6726U : NodeB Unavailable, SCTP Link Fault', 'SKT6726', 'Zone2', 'NOR-TAK', 'SA3', '14', '4/3/2014 16:24 �.', '5/3/2014 9:24 �.', '17:00', '09:11', '07:49', '1', '07:49', '', 'Stop Clock04/03/2014 23:49 K'Chittawan ����� ODU Failure ������¹���� ��������дǡ�չ���. Replace ODU Eclipse ���鹷ҧ TAK6526 Link TAK6526-TAK6726 site up alarm clear ;1$AT!SK1 Start time: 05/03/2014 09:00:00 Restoration time : 05/03/2014 09:24:00', '', '', '', '', 'Hardware - MW', 'Eclipse / ODU - damage', 'S', 'SKT6726', 'AT', 'IP MW', '07:49', 'Zone2', '')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Chittawan ����� ODU Failure ������¹���� ��������дǡ�չ���. Replace ODU ' at line 22
|
 |
 |
 |
 |
Date :
2014-06-07 17:53:23 |
By :
nPointXer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ยังไงครับ
|
 |
 |
 |
 |
Date :
2014-06-08 18:03:48 |
By :
nPointXer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีใครพอทราบอีกไหมครับ ตอนนี้ผมมืดไปหมดเลย ลองทุกวิธี ไม่รู้ลืมอะไรหรือเปล่า ข้อมูลเข้าไม่ครบเลย
|
 |
 |
 |
 |
Date :
2014-06-09 08:56:40 |
By :
nPointXer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|