Źródło:


Komentarze (0)


Ocena:
0

źródło pochodzi od: sympozjon

Opis:
Przekształca wyniku
zapytania Postgresql w xml

Język: php


<?
//------------------------------------------------------------------------- -----------------------------------------

// Description: This function handles postgres->xml data

// transformations.

// Author:  Cody McCain (mcm99c@acu.edu)

// License: GNU Public

// Last Updated: 5/7/2001

//

// Requirements: To use XML/XSLT with PHP you must have DOM XML

// (libxml-2.2.7) [www.xmlsoft.org],

// Sablot [www.gingerall.com] (or another xsl parser)

// compiled into PHP.

//

// This function does not require Sablot, but I encourage

// you to use XSLT stylesheets as this separates content

// from data (very important in multi-tier environment).

//

// Abstract: I am constantly transforming recordsets (SQL Query Results)

// so I can provide the appropriate data for my XSL stylesheets.

// This function takes a postgres query result and converts it

// to an XML DOM object.

//

// usage example:

//      $error = recordset_to_xml_ext ( $result, "items", "item",

// array ("field1", "field2"), $xmldoc );

//

// The xml document will be assigned to $xmldoc.

//

// You can convert select fields of the recordset to

// attributes instead of children of the respective row

// by including it in the attribute array.

//

//---------------------------------------------------------------- --------------------------------------------------



function recordset_to_xml_ext ( $result_query, $collection, $entry, $attributes, &$xmldoc )
{
// Make sure we have a valid  result from our query

// Check PostgreSQL functions for details on how to make database queries.


if( !$result_query )
{
trigger_error( "The query result passed was invalid.  Please check the SQL Query." );
return 1;
}

$fieldnum = pg_numfields( $result_query );
$rownum = pg_numrows( $result_query );

// Create array that lists all of our fields


for( $i=0; $i < $fieldnum; $i++ )
{
$fieldnames[] = pg_fieldname( $result_query, $i );
}

// Create new XML Document


$xmldoc = domxml_new_xmldoc("1.0");

if( strlen( $collection ) == 0 )
{
trigger_error( "Collection (root of xml) label cannot be null." );
return 1;
}

if( strlen( $entry ) == 0 )
{
trigger_error( "Entry (children of root in xml) label cannot be null." );
return 1;
}

// Here's where we add all the recordset to the xml document.


$xmlroot = $xmldoc->add_root( $collection );

for( $i=0; $i < $rownum; $i++ )
{
$row = pg_fetch_row( $result_query, $i );
$xmlentry = $xmlroot->new_child( $entry, "" );
for( $j=0; $j < $fieldnum; $j++ )
{
if( in_array( $fieldnames[$j], $attributes, false ) )
{
$xmlentry->set_attribute( $fieldnames[$j], $row[$j] );
}
else
{
$xmlentry->new_child( $fieldnames[$j], $row[$j] );
}
}
}

return 0;

}
?>
</body>
</html>
powrót

Tagi do źródła:
Przekształcenie wyniku zapytania Postgresql -> xml, postgresql, sql, bazy danych, php


Nikt jeszcze nie skomentował tego źródła.


assembler baza danych bot c crawler delphi html java kontakt box loader mail obsługa sieci obsługa zapyt(..) own os php pop3 porównywanie (..) przeszukiwanie(..) robot sieciowy rozmowa symulator rozm(..) system operacy(..) voteban stop wysyłanie e-m(..) boot dekodowanie mim(..) java juzef kolejny skrypt (..) mysql pobieranie zawa(..) przeglądanie e(..) sdl whois wysyłanie e-ma(..)

Wszystkie...


sources.pl to strona przeznaczona dla programistów, początkujących programistów i zupełnych amatorów programowania. Tu możesz umieścić swój kod, program napisany przez Ciebie, lub po prostu skomentować kod innego programisty.

Szukaj:


Źródeł: 30, oczekujących: 3, odrzuconych: 11

O stronie | kontakt |

Sources.pl

Ilość wejść: dzisiaj - 26 (unikalne: 25), ogółem - 686127 (unikalne: 611180)