硬盘克隆后无法访问MySQL数据库(本地)

时间:2019-05-18 12:17:07

标签: mysql mysql-error-1064

由于空间不足并需要更新,因此克隆了硬盘驱动器。问题是我无法使用脚本访问数据库。如果我访问/ localhost / phpmyadmin /,则可以访问,但是如果我运行脚本来上传数据库,则会出现此错误:

警告:mysqli_connect():(HY000 / 1045):在第2行的C:\ xampp \ htdocs \ csv \ Index2.php中,对用户'root'@'localhost'的访问被拒绝(使用密码:NO)

致命错误:未捕获错误:在C:\ xampp \ htdocs \ csv \ Index2.php:3中的bool上调用成员函数set_charset()堆栈跟踪:#0 {main}抛出在C:\ xampp \ htdocs中\ csv \ Index2.php在第3行

这是我的脚本的样子:

<?php  
$connect = mysqli_connect("localhost", "root", "", "fiverr_db");
$connect->set_charset('utf8');
if (!$connect)
    echo "Database Connection Failed<br>";
else
    echo "Database Connection successfull<br>";

if(isset($_POST["submit"]))
{
 if($_FILES['file']['name'])
 {
  $filename = explode(".", $_FILES['file']['name']);
  if($filename[1] == 'csv')
  {

   $handle = fopen($_FILES['file']['tmp_name'], "r");
   while($data = fgetcsv($handle))
   {
                $value1 =$data[0];
                $value2 =$data[1];
                $value3 =$data[2];
                $value4 =$data[3];
                $value5 =$data[4];
                $value6 =$data[5];
                $value7 =$data[6];
                $value8 =$data[7];
                $value9 =$data[8];
                $value10 =$data[9];
                $value11 =$data[10];  
                $value12 =$data[11];
                $value13 =$data[12];
                $value14 =$data[13];
                $value15 =$data[14];
                $value16 =$data[15];
                $value17 =$data[16];
                $value18 =$data[17];
                $value19 =$data[18];
                $value20 =$data[19];
                $value21 =$data[20];  
                $value22 =$data[21];
                $value23 =$data[22];
                $value24 =$data[23];
                $value25 =$data[24];
                $value26 =$data[25];
                $value27 =$data[26];
                $value28 =$data[27];
                $value29 =$data[28];
                $value30 =$data[29];
                $value31 =$data[30];  
                $value32 =$data[31];
                $value33 =$data[32];
                $value34 =$data[33];
                $value35 =$data[34];
                $value36 =$data[35];
                $value37 =$data[36];
                $value38 =$data[37];
                $value39 =$data[38];
                $value40 =$data[39];
                $value41 =$data[40];  
                $value42 =$data[41];
                $value43 =$data[42];
                $value44 =$data[43];
                $value45 =$data[44];
                $value46 =$data[45];
                $value47 =$data[46];
                $value48 = mysqli_real_escape_string($connect, $data[47]);
                $value49 = mysqli_real_escape_string($connect, $data[48]);
                $value50 = mysqli_real_escape_string($connect, $data[49]);
                $value51 =$data[50];  
                $value52 =$data[51];
                $value53 =$data[52];
                $value54 =$data[53];
                $value55 =$data[54];
                $value56 =$data[55];
                $value57 =$data[56];
                $value58 =$data[57];
                $value59 =$data[58];
                $value60 =$data[59];
                $value61 =$data[60];  
                $value62 =$data[61];
                $value63 =$data[62];
                $value64 =$data[63];
                $value65 =$data[64];
                $value66 =$data[65];
                $value67 =$data[66];
                $value68 =$data[67];

                $value1 = str_replace("'","",$value1);
                $value2 = str_replace("'","",$value2);
                $value3 = str_replace("'","",$value3);
                $value4 = str_replace("'","",$value4);
                $value5 = str_replace("'","",$value5);
                $value6 = str_replace("'","",$value6);
                $value7 = str_replace("'","",$value7);
                $value8 = str_replace("'","",$value8);
                $value9 = str_replace("'","",$value9);
                $value10 = str_replace("'","",$value10);
                $value11 = str_replace("'","",$value11);
                $value12 = str_replace("'","",$value12);
                $value13 = str_replace("'","",$value13);
                $value14 = str_replace("'","",$value14);
                $value15 = str_replace("'","",$value15);
                $value16 = str_replace("'","",$value16);
                $value17 = str_replace("'","",$value17);
                $value18 = str_replace("'","",$value18);
                $value19 = str_replace("'","",$value19);
                $value20 = str_replace("'","",$value20);                
                $value21 = str_replace("'","",$value21);
                $value22 = str_replace("'","",$value22);
                $value23 = str_replace("'","",$value23);
                $value24 = str_replace("'","",$value24);
                $value25 = str_replace("'","",$value25);
                $value26 = str_replace("'","",$value26);
                $value27 = str_replace("'","",$value27);
                $value28 = str_replace("'","",$value28);
                $value29 = str_replace("'","",$value29);
                $value30 = str_replace("'","",$value30);                
                $value31 = str_replace("'","",$value31);
                $value32 = str_replace("'","",$value32);
                $value33 = str_replace("'","",$value33);
                $value34 = str_replace("'","",$value34);
                $value35 = str_replace("'","",$value35);
                $value36 = str_replace("'","",$value36);
                $value37 = str_replace("'","",$value37);
                $value38 = str_replace("'","",$value38);
                $value39 = str_replace("'","",$value39);
                $value40 = str_replace("'","",$value40);                
                $value41 = str_replace("'","",$value41);
                $value42 = str_replace("'","",$value42);
                $value43 = str_replace("'","",$value43);
                $value44 = str_replace("'","",$value44);
                $value45 = str_replace("'","",$value45);
                $value46 = str_replace("'","",$value46);
                $value47 = str_replace("'","",$value47);
                $value48 = str_replace("'","",$value48);
                $value49 = str_replace("'","",$value49);
                $value50 = str_replace("'","",$value50);                
                $value51 = str_replace("'","",$value51);
                $value52 = str_replace("'","",$value52);
                $value53 = str_replace("'","",$value53);
                $value54 = str_replace("'","",$value54);
                $value55 = str_replace("'","",$value55);
                $value56 = str_replace("'","",$value56);
                $value57 = str_replace("'","",$value57);
                $value58 = str_replace("'","",$value58);
                $value59 = str_replace("'","",$value59);
                $value60 = str_replace("'","",$value60);                
                $value61 = str_replace("'","",$value61);
                $value62 = str_replace("'","",$value62);
                $value63 = str_replace("'","",$value63);
                $value64 = str_replace("'","",$value64);
                $value65 = str_replace("'","",$value65);
                $value66 = str_replace("'","",$value66);
                $value67 = str_replace("'","",$value67);
                $value68 = str_replace("'","",$value68);


                $query = "INSERT INTO `property_extend`(`Property ID`, `Listing Title`, `Property Type`, `Listing Type`, `Created Date`, `Last Scraped Date`, `Country`, `State`, `City`, `Zipcode`, `Neighborhood`, `Metropolitan Statistical Area`, `Currency Native`, `Average Daily Rate (USD)`, `Average Daily Rate (Native)`, `Annual Revenue LTM (USD)`, `Annual Revenue LTM (Native)`, `Occupancy Rate LTM`, `Number of Bookings LTM`, `Number of Reviews`, `Bedrooms`, `Bathrooms`, `Max Guests`, `Calendar Last Updated`, `Response Rate`, `Airbnb Response Time (Text)`, `Airbnb Superhost`, `HomeAway Premier Partner`, `Cancellation Policy`, `Security Deposit (USD)`, `Security Deposit (Native)`, `Cleaning Fee (USD)`, `Cleaning Fee (Native)`, `Extra People Fee (USD)`, `Extra People Fee (Native)`, `Published Nightly Rate (USD)`, `Published Monthly Rate (USD)`, `Published Weekly Rate (USD)`, `Check-in Time`, `Checkout Time`, `Minimum Stay`, `Count Reservation Days LTM`, `Count Available Days LTM`, `Count Blocked Days LTM`, `Number of Photos`, `Instantbook Enabled`, `Listing URL`, `Listing Main Image URL`, `Listing Images`, `Latitude`, `Longitude`, `Exact Location`, `Overall Rating`, `Airbnb Communication Rating`, `Airbnb Accuracy Rating`, `Airbnb Cleanliness Rating`, `Airbnb Checkin Rating`, `Airbnb Location Rating`, `Airbnb Value Rating`, `Pets Allowed`, `Integrated Property Manager`, `Amenities`, `HomeAway Location Type`, `Airbnb Property Plus`, `Airbnb Home Collection`, `License`, `Airbnb Property ID`, `Airbnb Host ID`)
                values('$value1','$value2','$value3','$value4','$value5','$value6','$value7','$value8','$value9','$value10','$value11','$value12','$value13','$value14','$value15','$value16','$value17','$value18','$value19','$value20','$value21','$value22','$value23','$value24','$value25','$value26','$value27','$value28','$value29','$value30','$value31','$value32','$value33','$value34','$value35','$value36','$value37','$value38','$value39','$value40','$value41','$value42','$value43','$value44','$value45','$value46','$value47','$value48','$value49','$value50','$value51','$value52','$value53','$value54','$value55','$value56','$value57','$value58','$value59','$value60','$value61','$value62','$value63','$value64','$value65','$value66','$value67','$value68')";
                mysqli_query($connect, $query);
    }
                $del_duplicate ="DELETE t1 FROM property_extend t1
        INNER JOIN
    property_extend t2 
WHERE
    t1.`Property ID` > t2.`Property ID` AND t1.`Property ID`= t2.`Property ID`;
    ";
    mysqli_query($connect, $del_duplicate);


   fclose($handle);
   echo "<script>alert('Import done');</script>";
  }
 }
}
?>  
<!DOCTYPE html>  
<html>  
 <head>  
  <title>For ES_Property_extend_MATCH_2019 File</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
 </head>  
 <body>  
  <h3 align="center">Import only es_Property_extend_MATCH_2019 Data from CSV File to Mysql</h3><br />
  <form method="post" enctype="multipart/form-data">
   <div align="center">  
    <label>Select CSV File:</label>
    <input type="file" name="file" />
    <br />
    <input type="submit" name="submit" value="Import" class="btn btn-info" />
   </div>
  </form>
 </body>  
</html>

您可能已经猜到我是个新手。预先感谢!

1 个答案:

答案 0 :(得分:0)

您可以检查数据库上的权限表吗?看来您可能遇到了用户名/密码问题。您可以分享以下内容吗?

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in C:\xampp\htdocs\csv\Index2.php on line 2

并且:

 Fatal error: Uncaught Error: Call to a member function set_charset() on bool in, C:\xampp\htdocs\csv\Index2.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\csv\Index2.php on line 3