Load,delimited,textfile,into,MySql,table,php

Mert 9/1/2016 0

Load delimited textfile into MySql table in PHP

PHP
<? 
# declare some variables 
$ServerName=''; 
$UserName=''; 
$Password=''; 
$filename=''; # Text file to read 
$TableName=''; # Table to be filled. 

mysql_connect("$ServerName", "$UserName", "$Password"); 

$fd = fopen($filename, "r"); 
while ($record = fgets($fd, 4096)) { 

$field = explode("|", $record); # '|' is the character which seperates the 
fields. 

$query = "INSERT INTO $TableName VALUES ($field[0], '$field[1]')"; #Use as many fields as you need. 
        $result = mysql_db_query("$ServerName", $query); 

    if ($result) { 
        echo "<p>$field[0] was added to the database</p>"; # Use any field you need. 
    } 

} 

fclose($fd); 

?>
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments