Pulling data from SQL, and writing to a text file

前端 未结 7 1148
广开言路
广开言路 2021-01-07 01:28

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<

7条回答
  •  爱一瞬间的悲伤
    2021-01-07 01:54

    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!";
    ?>
    

提交回复
热议问题