Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    problema importazione da dbf a mysql

    Salve, ho il seguente script per importare una tabella da DBF a MySQL

    codice:
    <?php$tbl = "articoli";
    $db_uname = 'Sql843621';
    $db_passwd = 'pwddatabase';
    $db = 'Sql843621_5';
    $conn = mysql_pconnect('62.149.150.195',$db_uname, $db_passwd);
    
    
    // Path to dbase file
    $db_path = "dbf/files/articoli.dbf";
    
    
    // Open dbase file
    $dbh = dbase_open($db_path, 0)
    or die("Error! Could not open dbase database file '$db_path'.");
    
    
    // Get column information
    $column_info = dbase_get_header_info($dbh);
    
    
    // Display information
    //print_r($column_info);
    
    
    $line = array();
    
    
    foreach($column_info as $col)
    {
    switch($col['type'])
    {
    case 'character':
    $line[]= "`$col[name]` VARCHAR( $col[length] )";
    break;
    case 'number':
    $line[]= "`$col[name]` FLOAT";
    break;
    case 'boolean':
    $line[]= "`$col[name]` BOOL";
    break;
    case 'date':
    $line[]= "`$col[name]` DATE";
    break;
    case 'memo':
    $line[]= "`$col[name]` TEXT";
    break;
    }
    }
    $str = implode(",",$line);
    $sql = "CREATE TABLE `$tbl` ( $str );";
    
    
    mysql_select_db($db,$conn);
    
    
    mysql_query($sql,$conn);
    set_time_limit(0); // I added unlimited time limit here, because the records I imported were in the hundreds of thousands.
    
    
    // This is part 2 of the code
    
    
    import_dbf($db, $tbl, $db_path);
    
    
    function import_dbf($db, $table, $dbf_file)
    {
    global $conn;
    if (!$dbf = dbase_open ($dbf_file, 0)){ die("Could not open $dbf_file for import."); }
    $num_rec = dbase_numrecords($dbf);
    $num_fields = dbase_numfields($dbf);
    $fields = array();
    
    
    for ($i=1; $i<=$num_rec; $i++){
    $row = @dbase_get_record_with_names($dbf,$i);
    $q = "insert into $db.$table values (";
    foreach ($row as $key => $val){
    if ($key == 'deleted'){ continue; }
    $q .= "'" . addslashes(trim($val)) . "',"; // Code modified to trim out whitespaces
    }
    if (isset($extra_col_val)){ $q .= "'$extra_col_val',"; }
    $q = substr($q, 0, -1);
    $q .= ')';
    //if the query failed - go ahead and print a bunch of debug info
    if (!$result = mysql_query($q, $conn)){
    print (mysql_error() . " SQL: $q
    \n");
    print (substr_count($q, ',') + 1) . " Fields total.
    
    
    ";
    $problem_q = explode(',', $q);
    $q1 = "desc $db.$table";
    $result1 = mysql_query($q1, $conn);
    $columns = array();
    $i = 1;
    while ($row1 = mysql_fetch_assoc($result1)){
    $columns[$i] = $row1['Field'];
    $i++;
    }
    $i = 1;
    foreach ($problem_q as $pq){
    print "$i column: {$columns[$i]} data: $pq
    \n";
    $i++;
    }
    die();
    }
    }
    }
    ?>
    quando faccio partire il file mi da il seguent eerrore:

    Fatal error: Call to undefined function dbase_open() in /web/htdocs/www.nomesito.it/home/dbf2mysql.php on line 12
    Questa è la line 12:

    codice:
    $dbh = dbase_open($db_path, 0)

    codice:
    $tbl = "articoli";  //(tabella nel db mysql)$db_uname = 'Sql843621'; 
    $db_passwd = 'pwddatabase';
    $db = 'Sql843621_5';
    $conn = mysql_pconnect('62.149.150.195',$db_uname, $db_passwd);
    
    
    // Path to dbase file
    $db_path = "dbf/files/articoli.dbf"; //(percorso del file dbf)
    
    
    // Open dbase file
    $dbh = dbase_open($db_path, 0) //riga di errore
    Che errore è?
    Come posso risolverlo?

    Grazie

  2. #2
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Il tuo php non ha la libreria che gestisce i DBF. Prova a vedere quali sono le estensioni caricate.

    Codice PHP:
    <?php
    echo '<pre>';
    echo 
    'LOADED EXTENSIONS:<br/>';
    print_r(get_loaded_extensions());
    echo 
    '</pre>';
    echo 
    phpinfo();
    ?>
    A quanto pare i dbf sono gestiti da PHP 5 < PHP 5.3.0
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  3. #3
    Infatti non è installata la libreria che gestisce i DBF.
    Come faccio ad installarla?
    Devo chiedere all'assistenza dove risiede l'hosting?

    Grazie

  4. #4
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Si.
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  5. #5
    ok
    Fatto.

    Grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.