Fix for Create a Node from a another Mysql DB Data

  1. <?php
  2. //exec("/usr/bin/clear");
  3. include_once('includes/bootstrap.inc');
  4. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  5. bootstrap_invoke_all('init');
  6. ini_set('memory_limit', '512M');
  7. //echo "Bootstrap sucessfull\n\n";
  8.  
  9. db_set_active('ssb');
  10. $results = db_query("SELECT * from beschaeftigung WHERE `id_art_beschaeftigung` =2");
  11. db_set_active('default');
  12. while($ssbdaten = db_fetch_array($results)){
  13.  
  14. $bezeichnung = $ssbdaten["bezeichnung_de"];
  15. $ansprechpartner_name = $ssbdaten["ansprechpartner_name"];
  16. $beschreibung_de = $ssbdaten["beschreibung_de"];
  17. $bereich = $ssbdaten["id_bereich_beschaeftigung"];
  18.  
  19.  
  20. $node = array();
  21.  
  22. $node['title'] = "$bezeichnung";
  23.  
  24. $node['type'] = "praktikumsplatz"; // all content types have names which are given at the time of the content type creation. visible at content types page when you drag your mouse over the list of content types
  25.  
  26. $node['name'] = "Admin";//not necessary
  27.  
  28. $node['body'] = "$beschreibung_de"; // You can remove the body field from your content type if you want.
  29.  
  30. //$node['field_bereich'] = array(array('value' => $bereich));
  31.  
  32. $node['status'] = 1;//stands for published=1 or unpublished=0 content
  33.  
  34. $node['uid'] = 1;//uid is user id, the user id 1 being the id of the one who makes first id after a drupal installation, uid 1 has all prvilleged, make sure your user id comes with all privileges,preferably use userid 1 to save yourself from the hassle.
  35.  
  36. $node['promote'] = 1; // promote =0 doesn't promote the content to the front page , whereas promote=1 promotes the content to the front page
  37.  
  38. $node['comment'] = 0; // comment 0=off , comment 1=readonly, comment 2=allowed
  39.  
  40. $node ['language'] = 'de'; // Spracheinstellung
  41.  
  42.  
  43. //$node['field_friendlytitle'] = array(array('value' => "$a4" ));// field_friendlytitle is the field I presumably created using cck for the content type. Notice how I am filling in the value for field_friendlytitle using array in an array.
  44.  
  45. $node['format'] = '2'; // inputformat, format=1 means Filtered HTML,format=1 means PHP code , format=2 means Full HTML
  46.  
  47. $node->field_ansprechpartner_name[0]['value'] = $ansprechpartner_name; // CCK Field
  48.  
  49. //You can also specify $node['nid'] followed by a number which will be the nid but I presume that it wont be of use to you at the moment. Not mentioning it will lead to a sequential auto generation whereas mentioning a static number will overwrite the old content each type you save the node!;
  50.  
  51.  
  52. $debug = 0;
  53.  
  54. //$debug = 1;
  55.  
  56.  
  57.  
  58.   if ($debug == 0) {
  59.  
  60.     node_save($node);
  61.  
  62.      print $node['title'].'... Saved<br><hr>';
  63.  
  64.    }
  65.  
  66.    elseif ($debug == 1) {
  67.  
  68.      print '<pre>';
  69. //      print_r($results);
  70.       print_r($node);
  71.         print '</pre>';
  72.   }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. //print_r($node)."<br>";
  79.  
  80. //unset($node);
  81. }
  82. ?>

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.