I am trying to pull data from SQL, and then write it to a text file. This does that, to an extent, but it only pulls 1 from the table, which reads test:test<
The file_put_contents() function overwrites the whole file - that's why you end up with only the last record each time.
You can use fopen() and fwrite() instead.
While a little more complicated than building a large string and using a single call to file_put_contents, this won't run out of memory if you have a lot of records.
";
// Or "$user:$pass\n" as @Benjamin Cox points out
fwrite($f, $accounts);
}
fclose($f);
echo "TEST!";
?>