2017-01-12 49 views
2

下面是我的程序,應該上傳一個文本文件到我的數據庫。我試圖上傳到數據庫的文件大約是308MB。當我嘗試運行這個程序時,它似乎完全運行,但是當我查看數據庫時,我沒有看到任何添加。所以我在$ db->東西中添加了它,以查看它會給出什麼錯誤並確保它連接到數據庫。PHP的mysql infile不工作

<?php 

set_time_limit(0); // unlimited max execution time 


$username = "root"; 
$auth = 'i-have-removed-it'; 
$db = $db = new mysqli("localhost", $username, $auth, 'testdb'); 
if(mysqli_connect_errno()) 
{ 
    die("Connection could not be established"); 
} 



print_r([ 
    "db->connect_errno1"  => $db->connect_errno, 
    "db->connect_error1"  => $db->connect_error, 
    "db->errno1"    => $db->errno, 
    "db->error1"    => $db->error, 
    "db->sqlstate1"   => $db->sqlstate, 
    "db->info1"    => $db->info, 
    "db->get_warnings1"  => $db->get_warnings(), 
]); 
$file = "./datafile_worldmap.txt"; 

$query = "load data infile '$file' 
into table `World_Map` 
character set ascii 
fields terminated by '|' 
lines terminated by '\r\n' 
ignore 1 lines 

(`GeoID`, `X`, `Y`, `Wood`, `Clay`, `Iron`, `Stone`, `Food`, `TerrainSpecificTypeID`, `TerrainCombatTypeID`, `RegionID`) 
"; 

$result = $db->query($query); 
print_r([ 
    "db->connect_errno2"  => $db->connect_errno, 
    "db->connect_error2"  => $db->connect_error, 
    "db->errno2"    => $db->errno, 
    "db->error2"    => $db->error, 
    "db->sqlstate2"   => $db->sqlstate, 
    "db->info2"    => $db->info, 
    "db->get_warnings2"  => $db->get_warnings(), 
]); 

$total_num_rows = $result->num_rows; 

echo "The Results Are : <br>"; 

?> 

輸出

Array 
(
    [db->connect_errno1] => 0 
    [db->connect_error1] => 
    [db->errno1] => 0 
    [db->error1] => 
    [db->sqlstate1] => 00000 
    [db->info1] => 
    [db->get_warnings1] => 
) 
Array 
(
    [db->connect_errno2] => 0 
    [db->connect_error2] => 
    [db->errno2] => 1045 
    [db->error2] => Access denied for user 'User'@'%%%.%%%.%%%.%%%' (using password: YES) 
    [db->sqlstate2] => 28000 
    [db->info2] => 
    [db->get_warnings2] => 
) 

消息錯誤

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>500 Internal Server Error</title> 
</head><body> 
<h1>Internal Server Error</h1> 
<p>The server encountered an internal error or 
misconfiguration and was unable to complete 
your request.</p> 
<p>Please contact the server administrator, 
<<email>> and inform them of the time the error occurred, 
and anything you might have done that may have 
caused the error.</p> 
<p>More information about this error may be available 
in the server error log.</p> 
<p>Additionally, a 500 Internal Server Error 
error was encountered while trying to use an ErrorDocument to handle the request.</p> 
</body></html> 
+1

使用此LOAD DATA LOCAL INFILE而不是加載數據infile – JYoThI

+0

將此作爲答案,因爲這正是我所需要的。非常感謝你!!! – kodabear

+1

您的歡迎。我發佈爲答案 – JYoThI

回答

1

添加LOCAL到您的發言

使用此LOAD DATA LOCAL INFILE而不是load data infile

+0

嗯,它似乎填滿了數據庫的東西,但當我看着表,我沒有看到它的任何東西,但它仍然佔用空間 – kodabear

+1

您的領域終止|這是對的嗎 ? – JYoThI

+0

它應該是。我想我會運行它與樣本文件,看看會發生什麼 – kodabear

0

您需要增加文件上傳大小。默認文件上傳大小爲2MB 以下是這需要改變的變量:

memory_limit = 500M 
upload_max_filesize = 200M // 200MB file size 
post_max_size = 500M // increase your post limit to 500 MB 

利用這一點,你可以可以上傳文件,200MB

的最大尺寸