Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 17th, 2012  |  syntax: None  |  size: 1.12 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. XML with mySQL and DOM
  2. Input data: "davidjmorin"
  3. Data inserted: "http://someurl.com/davidjmorin"
  4.        
  5. <?
  6. //header('Content-type: text/xml');
  7.  
  8. $link = mysql_connect('localhost','root','IhaveAlLthEanSwers2012!');
  9. mysql_select_db('bb_links');
  10.  
  11. $sql = "Select * from `links`";
  12. $run = mysql_query($sql, $link);
  13.  
  14. if( $run && mysql_num_rows( $run ) ) {
  15. $doc = new DOMDocument( '1.0' );
  16. $doc->formatOutput = true;
  17. $doc->preserveWhiteSpace = true;
  18.  
  19. $root = $doc->createElement( 'data' );
  20. $doc->appendChild( $root );
  21.  
  22. while( ( $fetch = mysql_fetch_assoc( $run ) )!== false ) {
  23.     $node = $doc->createElement( 'channel' );
  24.     $root->appendChild( $node );
  25.  
  26.     foreach( $fetch as $key => $value ) {
  27.         createNodes( $key, $value, $doc, $node );
  28.     }
  29. }
  30. $doc->save("thelinks.xml");
  31. }
  32. //$node = "channel";
  33. function createNodes( $key, $value, $doc, $node ) {
  34. $key = $doc->createElement( $key );
  35. $node->appendChild( $key );
  36. $key->appendChild( $doc->createTextNode( $value ) );
  37. }
  38. ?>
  39.        
  40. <?php
  41.     $url_name = "http://www.example.com/";
  42.     $data = $_POST['name']; //davidjmorin
  43.     $data_to_insert = $url_name . $data;
  44.     //Insert data into database
  45. ?>