max_allowed_packet Size

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • max_allowed_packet Size

    Hi,

    die csv Datei die ich in meine MYSQL DB importieren will ist zu groß und überschreitet anscheinend die max_allowed_packet Size.

    Aber wenn ich den Befehl

    mysql> mysql --max_allowed_packet=32M

    in meine Import-PHP Datei einbinde geht die Datei nicht mehr.

    Der Inhalt der Datei sieht so aus :

    PHP-Code:
    <?php

    // ======================================================================
    //  CSV MySQL Converter                                   Begin: 03/17/04
    // ======================================================================
    //  Version 1.5
    //  by Matthew Forest (matt@cyangarden.com)
    //
    // ======================================================================
    //  TERMS OF USAGE
    // ======================================================================
    //  You are free to use this script in any way you want, no warranties
    //  are expressed or implied. This works for me, but I don't guarantee
    //  that it works for you, USE AT YOUR OWN RISK.
    //
    // ======================================================================
    //  DESCRIPTION
    // ======================================================================
    //  This script transfers the contents of a CSV file into a MySQL table.
    //
    //  It can be run from a web browser, or used in a cron job and will only
    //  output a brief result. Upon error, mysql_error() is used to provide
    //  more precise information.
    //
    // ======================================================================
    //  INSTALLATION
    // ======================================================================
    //  All you have to do before running this PHP script is create a table
    //  with exactly the same column count as there are in the CSV file. For
    //  example a CSV file containing
    //
    //  Value 1;Value 2;Value 3
    //
    //  will require a respective MySQL table like this one:
    //
    //  CREATE TABLE mydata (
    //      column1 VARCHAR(255) NOT NULL,
    //      column2 VARCHAR(255) NOT NULL,
    //      column3 VARCHAR(255) NOT NULL
    //  );
    //
    // ======================================================================
    //  VERSION HISTORY
    // ======================================================================
    //  04/28/04 - Joined all SQL inserts into one for better performance
    //           - Allowed external URL as the CSV source file
    //  03/17/04 - Initial release

        // Database server host
    $sql_db['host'] = "localhost";

        
    // Database name
    $sql_db['name'] = "XXXXXXX";

        
    // Database user name
    $sql_db['user'] = "XXXXXXX";

        
    // Database password
    $sql_db['pass'] = "XXXXXXXXXXXXX";

        
    // Database table na

    me
    $sql_db
    ['tble'] = "bstatnations";


        
    // Absolute path or URL (e.g. [url]http://...[/url]) 
    // to the CSV file
    $csv_file['path'] = "ip-to-country.csv";

        
    // Value Separator used in CSV file
    $csv_file['sepa'] = ",";


    // ======================================================================
    //  Connect to MySQL database
    // ======================================================================

    $connect = @mysql_connect($sql_db['host'], $sql_db['user'], $sql_db['pass'])
        or die(
    mysql_error());

    $db = @mysql_select_db($sql_db['name'], $connect)
        or die(
    mysql_error());


    // ======================================================================
    //  Create the SQL Insert Query
    // ======================================================================

    $file_contents_line = @file($csv_file['path'])
        or die (
    "CSV file not found.");

    foreach (
    $file_contents_line as $key => $val)
    {
            
    // Skip empty lines
        
    if (empty($val)) continue;
        
        
    $inserts .= (($key >= 1) ? ", " "")."('";

        
    $values explode($csv_file['sepa'], $val);
        
        for (
    $j 0$j count($values); $j++)
        {
            
    $inserts .= addslashes(utf8_decode($values[$j])).(($j != 
    (
    count($values) - 1)) ? "', '" "");
        }

        
    $inserts .= "')";
    }


    // ======================================================================
    //  Store all data into our database
    // ======================================================================

    $sql "INSERT INTO ".$sql_db['tble']."
            VALUES "
    .$inserts;

    $res mysql_query($sql)
        or die(
    mysql_error());


    echo 
    "Convert successful.\n";

    ?>
    Ich hab den Befehl einfach irgendwo eingebunden, aber das hat nix gebracht

    Wo muss ich den mysql> mysql --max_allowed_packet=32M Befehl eingeben ?
    Zuletzt geändert von MacFan; 28.01.2006, 15:53.

  • #2
    In PHP gar nicht, eher auf der Konsole, das ist ein Server-Parameter. RTFM!

    Kommentar


    • #3
      Als Webspace User von HostEurope kann ich da wohl nix machen

      Kann ich denn sehen, wie groß das Limit gerade gesetz ist ?

      Oder kann ich die csv Datei in mehrere Dateien splitten ?

      Kommentar

      Lädt...
      X