note 50575 added to function.fwrite
| From: | goncalvesattedabliodotcomdotbr at osu1 dot php dot net | Date: | Thu, 03 Mar 2005 19:38:01 +0000 |
| Subject: | note 50575 added to function.fwrite | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85885@lists.php.net to get a copy of this message | ||
esta funcao cria um arquivo "meuarquivo.csv" no formato csv de acordo com os campos da
tabela do select !
[POSTGRESQL]
<?
$filename = "meuarquivo.csv";
$Arquivo = fopen($filename, 'w+')
$sql="select * from tabela";
$socket = pg_connect(host=[servidor] port=[porta] dbname=[banco de dados] user=[usuario]
password=[senha], $sql);
////////////////// nome dos campos
for ($a=0;$a < pg_numfields($rs);$a++){
$mLinha .= '"' . pg_fieldname($rs,$a) . '"' . ',';
}
$mLinha .= "\n";
fwrite($Arquivo, $mLinha);
//////////////////////////
/////////////////////////// registros
for ($i=0 ;$i < pg_numrows($rs); $i++){
$ln=pg_fetch_array($rs, $i);
$mLinha = "";
for ($a=0;$a < pg_numfields($rs);$a++){
$mAspas = "";
if (pg_fieldtype($rs,$a) == 'varchar' or pg_fieldtype($rs,$a) == 'date'){
$mAspas = '"';
}
$mLinha .= $mAspas . $ln[pg_fieldnum($rs,pg_fieldname($rs,$a))] . $mAspas . ',';
}
$mLinha .= "\n";
fwrite($Arquivo, $mLinha);
}
///////////////////////////////////////
fclose($Arquivo);
?>
----
Manual Page -- http://www.php.net/manual/en/function.fwrite.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50575
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50575&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50575&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50575&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50575&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50575&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50575&report=yes
Search -- http://master.php.net/manage/user-notes.php