scusmai.. vedendo che avevi
nome=valorenome.. l'avevo preso per un ini.. ^_^
ho uno scriptino che fa per te..
Codice PHP:
<?php
################################
## CONFIGURAZIONE ##
################################
//imposta opportunamente le variabili qui sotto
$_CFG['file'] = 'file.txt';
$_CFG['separatore'] = ',';
$_CFG['db_host'] = 'localhost';
$_CFG['db_user'] = 'root';
$_CFG['db_pwd'] = 'root';
$_CFG['db_name'] ='database';
$_CFG['db_table'] = 'tabella';
################################
## FINE CONFIGURAZIONE ##
################################
//non modificare qui sotto
function mysql_table_exists($database, $tableName)
{
$tables = array();
$tablesResult = mysql_query("SHOW TABLES FROM $database;");
while ($row = mysql_fetch_row($tablesResult)) $tables[] = $row[0];
return(in_array($tableName, $tables));
}
ob_start();
if(!file_exists($_CFG['file']) || !is_readable($_CFG['file']))
{
echo "Impossibile aprire in lettura il file di input ({$_CFG['file']})
controllare la configurazione dello script";
exit;
}
@mysql_connect($_CFG['db_host'],$_CFG['db_user'],$_CFG['db_pwd']) or die("Impossibile connettersi a mysql, verificare host username e password
".mysql_error());
@mysql_select_db($_CFG['db_name'])or die("Impossibile selezionare il database \"{$_CFG['db_name']}\"");
if(!mysql_table_exists($_CFG['db_name'],$_CFG['db_table']))
{
echo "Impossibile trovare la tabella \"{$_CFG['db_table']}\" nel database \"{$_CFG['db_name']}\"
controllare la configurazione dello script";
exit;
}
$righe = file($_CFG['file']);
$newrighe = array();
foreach ($righe as $riga) if(trim($riga) !='') $newrighe[] = $riga;
echo 'Inserimento di '.count($newrighe).' record in corso....
';
flush();
ob_flush();
$ins = 0;
foreach ($newrighe as $riga)
{
$contenuto = explode($_CFG['separatore'],$riga);
$values='';
foreach ($contenuto as $elem)
$values .= "'".mysql_escape_string($elem)."',";
$values = substr($values, 0, -1);
$sql = "INSERT INTO `{$_CFG['db_table']}` VALUES ($values);";
if(!mysql_query($sql)) echo "problemi con la query \"$sql\"
motivo: [b]".mysql_error().'[/b]
';
else $ins++;
}
mysql_close();
echo "Inseriti con successo $ins record";
?>