Convert text file to mysql table issue!!
Posted: Thu Feb 11, 2010 1:47 pm
Hello again, php technorati. Ok I am trying to add a text email list to MYSql. I found a script that will do it but it has two fields instead of one which i need. Here is the code:
Can someone modify this so that it will only add email addresses to one column in mysql -variable = $email?
As always, Thanks in advance,
Batoe
Code: Select all
function convert( $delimeter = '\t', $filename, $db['host'], $db['user'], $db['passwd'], $db['database'], $db['table'] )
{
//
//Lets get the databse up and working
//
$cid = mysql_connect( $db['host'], $db['user'], $db['pass'] ) or die( 'Cant connect to mysql' );
mysql_select_db( $db['database'], $cid ) or die( 'Cant find database' );
ini_set('MAX_EXECUTION_TIME', 900); // Nessecary as the values may be too much for the server
$file = file( $filename );
foreach ($file as $line)
{
$array = explode($delemeter, $line);
$count = count($array);
for ($x=0; $x<$count; $x++)
{
$array[$x] = trim( addslashes( str_replace( '|', '', $array[$x] ) ) ); //clean up crew
if( ( $x+1 )!= $count )
{
$comma = ',';
}
$values = "'".$array[$x]."'".$comma;
}
$result = mysql_query( insert into ' . $db['table'] . ' values ( ' . $values . ' );, $cid);
}
}
?>As always, Thanks in advance,
Batoe