Jump to content

[SOLVED] Run a query for each line?


papaface

Recommended Posts

Hello,

How would I run a query for each line in a text file?

I have this so far but it doesnt work:

<?php

mysql_connect("localhost","xxx","xxx") or die (mysql_error());
mysql_select_db("xxxx") or die (mysql_error());

$filename = "file.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);

foreach($contents as $line_num => $line)
{
mysql_query("insert into cats (category) values ('{$line}')") or die(mysql_error());
}

?>

Link to comment
https://forums.phpfreaks.com/topic/54373-solved-run-a-query-for-each-line/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.