I make the following query from my apache server on a 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 .txt file on my apache server, eg:
/var/www/html/sistema/export/resultado.txt
How could you do this type of process automatically?