Convert text file to mysql table issue!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Convert text file to mysql table issue!!

Post by cap2cap10 »

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:

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);
    }
 
}
?>
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
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Convert text file to mysql table issue!!

Post by cap2cap10 »

Ok, guys. Disregard. I converted file to CSV file and added to mysql database!!!!! :drunk: Will wonders ever cease!!


Thanks again,

Batoe
Post Reply