Location: PHPKode > scripts > SQL2TXT > sql2txt/example.php
<html>
<? require("sql2txt.php"); ?>

<?

// this is an array with column lenghts-alignment of TXT file
$myarray = array("10-left", "40-left", "20-left", "20-right");

// SQL instruction that will select data to write into TXT file
$sql = "select id, name, phone, income from customer where income>10000";

$header = "HEADER OF TXT FILE";  // HEADER
$trailer = "TRAILER OF TXT FILE";  // FOOTER

// the class is inhearited
$conversao = new sql2txt;

// 1 - DBase name
// 2 - port
// 3 - DbUser
// 4 - PassWord
$ok = $conversao->openSQL("dbname", "5432", "username", "password");
echo($ok);

// Open the SQL file for write
$ok = $conversao->opentxt("destination.txt");
echo($ok);

// Get the Columns and write it into a SQL file
// 1 - SQL instructions
// 2 - array with lenghts/alignments
// 3 - header
// 4 - trailer
$conversao->InsertColumnsIntoTXT( $sql, $myarray, $header, $trailer );

// Close TXT and SQL files
$conversao->Closeall();
?>
</html>
Return current item: SQL2TXT