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<
Others have answered the why it is only writing one content into the file, this is more of a suggestion but if you want to record the actual user and password, instead of:
$accounts = "$user:$pass
";
use
$accounts = $user . ":" . $pass . "\n";
but if you already knew that and were using that for debugging purposes then disregard this.
Good luck