Return to Snippet

Revision: 17149
at August 25, 2009 10:45 by fackz

Initial Code
$conn = mysql_connect('localhost', 'username', 'password') or die ('Error connecting to mysql');
mysql_select_db('dbname', $conn) or die ('Error connecting to database');
$query = 'insert into titulos (nome) values ("%s");';

$lines = file('filmes.txt');//your filename
for($i=0; $i < count($lines); $i++){
mysql_query(sprintf($query, mysql_real_escape_string($lines[$i]))) or die(mysql_error() . '<br><br>' . '<b>Query:</b> ' . $query);

Initial URL

Initial Description
This piece of code will store each line of a txt file into a mysql database

Initial Title
Import data from TXT file to Mysql

Initial Tags
mysql, file, text

Initial Language