2017-01-24 1 views
0

Ich verstehe, dass es viele andere ähnliche Fragen gibt, aber ich habe ziemlich viel in alle anderen Beiträge und alle anderen untersucht Vorschläge haben nicht funktioniert.Ich versuche, eine MySQL-Tabelle zu exportieren, aber ich empfange - secure-file-priv

Ich bin derzeit mit einer macOS Sierra Version 10.12.2

MySQL Version 5.7.17

SELECT @@ GLOBAL.secure_file_priv; und SHOW VARIABLES LIKE "secure_file_priv"; zeigen secure_file_priv = auf NULL.

Ich habe keine my.cnf-Datei auf meinem System (finden: my.cnf: Keine solche Datei oder das Verzeichnis)

ich viele Beiträge gelesen habe, die den Wert von secure_file_priv Ändern erwähnt, aber ich bin nicht in der Lage es zu finden.

Die folgenden Beiträge hier ich angesprochen haben:

Solution 1

Solution 2

Solution 3

Ich wünschte, dieses war beantwortet, wie es meine Situation betrifft:

Solution 4

Solution 5

Am Ende des Tages ist es wie das Ändern secure_file_priv aussieht, ist der Ort zu beginnen, ich kann es einfach nicht finden.

Ich bin sicher, dass die OUTFILE Speicherort für die oben genannten möglicherweise falsch ist, aber das ist, weil ich nicht weiß, wo ich Dateizugriff habe, weil ich nicht weiß, wie sicher secure_file_priv zu ändern.

Antwort

1

Also beschloss ich, mir keine Gedanken über die Befehlszeile zu machen und erstellte eine PHP-Datei, die die MySQL-Datenbank direkt nach Excel exportiert.

Lösung aus der folgenden inspiriert: (dieses Geck etwas Liebe!)

Autor: Shahroze Nawaz

Datum: 8. November 2016

Titel: Importieren Und CSV-Dateien mit PHP und MySQL exportieren

URL : https://www.cloudways.com/blog/import-export-csv-using-php-and-mysql/

Dies ist der Haupt index.php

<pre> 

    <!DOCTYPE html> 
    <html lang="en"> 

    <head> 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" crossorigin="anonymous"> 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" crossorigin="anonymous"> 
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" crossorigin="anonymous"></script> 
    </head> 

    <body> 
     <div id="wrap"> 
      <div class="container"> 
       <div class="row"> 

     <!--Database Table Display--> 
        <?php 
         include 'database_table.php'; 
        ?> 
     <!--End Import Form Button--> 

     <!--Export Form Button--> 
        <form class="form-horizontal" action="export.php" method="POST" name="upload_excel" 
          enctype="multipart/form-data"> 
         <div class="form-group"> 
          <div class="col-md-4 col-md-offset-4"> 
           <input type="submit" name="Export" class="btn btn-success" value="Export to Excel"/> 
          </div> 
         </div>      
        </form> 
     <!--End Export Form Button--> 

       </div> 
      </div> 
     </div> 
    </body> 

    </html> 

</pre> 

Und das ist die export.php, dass die Form Aktion:

<pre> 
     $dbhost = "******"; 
     $dbuser = "******"; 
     $dbpass = "******"; 
     $dbname = "******"; 
     $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); 

     $selection = "SELECT * <table name>"; 
     $result = mysqli_query($connection, $selection); 

     if(isset($_POST["Export"])) { 
      header('Content-Type: text/csv; charset=utf-8'); 
      header('Content-Disposition: attachment; filename = leads.csv'); 

      $output = fopen("php://output", "w"); 
      fputcsv($output, array('ID', 'First Name', 'Last Name', 'Email', 'Phone', 'State', 'Specialty', 'Sourcecode', 'Date')); 

      while($row = mysqli_fetch_assoc($result)) { 
       fputcsv($output, $row); 
      } 
      fclose($output); 
     } 
</pre> 

Und hier ist die Datenbanktabelle in der gedruckten Index.php-Datei, die die MySQL-Datenbank mit den Bootstrap-Formaten anzeigt:

<pre> 

    <?php 
     $dbhost = "******"; 
     $dbuser = "******"; 
     $dbpass = "******"; 
     $dbname = "******"; 
     $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); 

     $selection = "SELECT * <table name>"; 
     $result = mysqli_query($connection, $selection); 

     if (mysqli_num_rows($result) > 0) { 
       echo "<div class='table-responsive'> 
          <table id='myTable' class='table table-striped table-bordered'> 
           <thead> 
             <tr> 
              <th>ID</th> 
              <th>First Name</th> 
              <th>Last Name</th> 
              <th>Email</th> 
              <th>Phone</th> 
              <th>State</th> 
              <th>Specialty</th> 
              <th>Sourcecode</th> 
              <th>Time</th> 
             </tr> 
           </thead> 

           <tbody>"; 
           while($row = mysqli_fetch_assoc($result)) { 
             echo "<tr> 
              <td>" . $row['id']."</td> 
              <td>" . $row['first_name']."</td> 
              <td>" . $row['last_name']."</td> 
              <td>" . $row['email']."</td> 
              <td>" . $row['phone']."</td> 
              <td>" . $row['state']."</td> 
              <td>" . $row['specialty']."</td> 
              <td>" . $row['source_code']."</td> 
              <td>" . $row['date_submitted']."</td> 
             </tr>";   
          } 

           echo "</tbody> 
          </table> 
        </div>"; 

     } else { 
       echo "You have no records..."; 
     } 
    ?> 

</pre> 
Verwandte Themen