如何解决此消息访问被拒绝用户'dbtsorder'@'localhost'(使用密码:YES)此消息仅在localhost上在线工作正常 我尝试从csv文件加载文件,此消息仅出现在此代码
的位置数据库连接:
$host="localhost";
$user="dbtsorder";
$password="M@07765729s";
$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";}}
}
答案 0 :(得分:0)
因此,通过查看我的Crystalball,问题似乎与您的权限有关。 在mySql中,您可以选择将某些客户列入白名单,建议您从http://dev.mysql.com/doc/refman/5.7/en/create-user.html读取以了解用户的工作方式
下一步是阅读以下内容,详细了解权限http://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html
的含义“为dbtsorder显示资助”的输出是什么
答案 1 :(得分:0)
错误显示存在连接问题,请检查 dbtsorder 用户是否可以访问 tsorder 或不。如果没有,则首先授予此用户访问特定数据库的权限。
答案 2 :(得分: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);
}
使用此代码,这将适合您, $ data [0] 是第一列,第二列使用$ data [1]等。