3
I do the following query of my apache server in an SQL SERVER database:
<?php
// Dados do banco
$dbhost = "192.168.0.100"; #Nome do host
$db = "DATABASE"; #Nome do banco de dados
$user = "root"; #Nome do usuáo
$password = "root"; #Senha do usuáo
@mssql_connect($dbhost,$user,$password) or die("Nãfoi possíl a conexãcom o servidor!");
@mssql_select_db("$db") or die("Nãfoi possíl selecionar o banco de dados!");
$instrucaoSQL = "SELECT
A.CODIGO AS COD,
B.chapa AS CHAPA,
A.nome AS NOME,
REPLICATE('0', 11 - LEN(A.cpf)) + RTrim(A.cpf) AS CPF,
B.CODFILIAL AS LOJA
FROM
PPESSOA AS
A LEFT OUTER JOIN PFUNC as B on
A.CODIGO = b.CODPESSOA
WHERE B.CODSITUACAO<>'D'
ORDER BY CHAPA";
$consulta = mssql_query($instrucaoSQL);
$numRegistros = mssql_num_rows($consulta);
echo "Esta tabela contém $numRegistros registros!\n<hr>\n";
if ($numRegistros!=0) {
while ($row = mssql_fetch_array($consulta)) {
echo $row['COD']."-".$row['CHAPA']."-".$row['NOME']."-".$row['CPF']."-".$row['LOJA']."\n<br>\n";
}
}
?>
I need to save the result inside a folder in a file . txt on my apache server,example:
/var/www/html/sistema/export/resultado.txt
How could I do this kind of process automatically?
file_put_contents()
can help to create the file.– rray
file_put_contents is a function that replaces fope fwrite and fclose, according to an article fwrite works faster, and better with large files, than file_put_contents , there is a topic about this in the English stackoverflow with the article: http://stackoverflow.com/questions/6415958/whats-faster-file-put-contents-fopen-fwrite-fclose
– Leonardo Rodrigues