Assuming Mysqli
$conn = new mysqli($servername, $username, $password, $dbname);
$query = "SELECT nome_coluna FROM nome_tabela";
$result = mysqli_query($conn,$query);
$k=1;
$i=1;
while($row = mysqli_fetch_assoc($result)) {
$res = $row["nome_coluna"]."\n";
file_put_contents("arquivo".$i.".txt", $res, FILE_APPEND);
//nos multiplos de 18000 muda o nome do arquivo acima
if (($k%18000)==0){
$i=$i+1;
}
$k=$k+1;
}
put_contents - writes a string to a file, if this file does not yet exist it creates the file.
FILE_APPEND
- adds the data to the file instead of overwriting it.
With already discontinued Mysql: - as requested in the comment
$conn = mysql_connect("localhost","USUARIO","SENHA");
mysql_select_db("nome_DB", $conn);
$query = mysql_query("SELECT nome_coluna FROM nome_tabela");
$k=1;
$i=1;
while($row = mysql_fetch_array($query)){
$res = $row["nome_coluna"]."\n";
file_put_contents("arquivo".$i.".txt", $res, FILE_APPEND);
if (($k%18000)==0){
$i=$i+1;
}
$k=$k+1;
}
I think what you want is this: https://www.w3schools.com/php/php_file_create.asp
– Tiago Boeing
If any answer has served you read this post https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252