2016-09-09 66 views
0

如何解決此消息拒絕用戶'dbtsorder'@'localhost'的訪問(使用密碼:YES)此消息僅在本地主機上顯示細 我嘗試從csv文件在文件加載和僅在該代碼是拒絕訪問用戶'dbtsorder'@'localhost'(使用密碼:YES)

數據庫連接此消息出現:

$host="localhost"; 
$user="dbtsorder"; 
$password="[email protected]"; 
$db="tsorder"; 
$conn=mysqli_connect($host,$user,$password,$db); 
mysqli_query($conn,"SET NAMES utf8"); 
mysqli_set_charset($conn,'utf8') 

/*************** **********************/

加載文件代碼:

if(isset($_POST['submit'])){ 
    $link = realpath('/var/www/order/projectmanagment/'); 
    $checklist = $link.'checklist.csv';  
$username=$_SESSION['username']; 
$query=mysqli_query($conn,"select* from tbl_user where db_username='$username'")or die(mysqli_error($conn)); 
$res=mysqli_fetch_array($query); 
$fname=$res['db_fname']; 
$lname=$res['db_lname']; 
$name=$res['db_fname'].' '.$res['db_lname']; 
    $projectname=$_POST['dep']; 
    $location=$_POST['cname']; 
    $psd=$_POST['txt_psd']; 
    $pdd=$_POST['txt_pdd']; 
    $past=$_POST['txt_past']; 
    $padd=$_POST['txt_padd']; 
    $duration=$_POST['duration']; 
    $aduration=$_POST['txt_aduration']; 
    $pnote=$_POST['txt_pnote']; 
    $transferredto=$_POST['txt_transferredto']; 
    $client=$_POST['txt_client']; 
    $cpercentage=$_POST['txt_cpercentage']; 
    $epercentage=$_POST['txt_epercentage']; 
    $mpercentage=$_POST['txt_mpercentage']; 
    $sum=$cpercentage+$epercentage+$mpercentage; 
    if($projectname=="" || $location=="" || $psd=="" || $pdd=="" || $client==""){ 
     echo"Enter All Information."; 
     } 
     else{ 
     if($sum==100){  
      $_SESSION['projectname']=$projectname; 
$sql=mysqli_query($conn,"INSERT INTO tbl_project(db_projectname,db_location,db_transferredto,db_psd,db_pdd,db_duration,db_past,db_padd,db_aduration,db_pnote,db_user,db_client,db_cpercentage,db_epercentage,db_mpercentage)VALUES('$projectname','$location','$transferredto','$psd','$pdd','$duration','$past','$padd','$aduration','$pnote','$name','$client','$cpercentage','$epercentage','$mpercentage')")or die(mysqli_error($conn)); 

$import=mysqli_query($conn,"LOAD DATA INFILE '$checklist' INTO TABLE tbl_checklist FIELDS TERMINATED BY ',' 
     OPTIONALLY ENCLOSED BY '\"' 
     LINES TERMINATED BY '\n' set db_projectname='$projectname' ")or die(mysqli_error($conn)); 
header("location:allproject.php?msg=2"); 

}else{echo"Percentage should be equal to 100";}} 
     } 
+2

您的在線數據庫沒有用戶'dbtsorder @ localhost'使用該密碼,或者它無權訪問tsorder數據庫。 – aynber

+0

你可以發佈你的my.cnf我有一個想法是什麼錯誤可能是 – Jeredepp

+0

生產憑證?你需要授予訪問'dbtsorder'的權限 – devpro

回答

0

您可以使用此代碼來讀取CSV文件,將數據插入數據庫

$row=1; 
if (($handle = fopen("test.csv", "r"))!== FALSE) { 
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
{ 
    $num = count($data);  
    $row++; 
    if($row>2) 
    { 
     if($data[0]!="") 
     { 
     //write your inset query 
     } 
    } 
} 
fclose($handle); 
} 

用戶驗證碼這會爲你工作, $數據[0]是第一列中,第二次使用$ data [1]等

+0

非常感謝這是工作:) –

0

錯誤明顯顯示出有連接問題的輸出,請wheather dbtsorder用戶tsorde的訪問否或不。如果沒有,那麼首先讓這個用戶訪問特定的數據庫。

+0

如果是一個連接問題,爲什麼其他頁面沒有相同的消息,爲什麼我可以讀取和插入,更新和從數據庫中刪除只有在我使用負載文件中的頁面我有這個問題是否有任何其他代碼可以我從一個CSV文件讀取並插入數據庫? –

+0

請在我的下一個答案中找到csv閱讀器代碼@mohamadmohamad –

相關問題