1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
<?
/* Topic: Create XML files using PHP DOM-XML
*/
// create the xml processing instruction
$doc = new_xmldoc("1.0" );
$filename="stock";
$filedate = strftime("%y%m%d") ;
global $i ;
$root = $doc->add_root("racine" );
date = strftime("%d/%m/%C%y") ;
$dbName = "mabase";
$dbUser = "nobody";
$dbPass = "nobody";
$host = "127.0.0.1";
$port = "5432";
$cnxString = "host=".$host." port=".$port." dbname=".$dbName." user=".$dbUser." password=".$dbPass;
$pgsql_conn = pg_connect($cnxString);
if ($pgsql_conn)
{
echo "Connexion reussie : \n";
$query = "SELECT office_id , office_name FROM office where office_id like 'A%'";
$result = pg_exec($query) or die('echec requete : ' . pg_last_error());
$cpt = 0;
$i = 1 ;
while ($i>0 && $line = pg_fetch_array($result))
{
$line = pg_fetch_array($result);
foreach ($line as $col_value)
{
$officename=$line[1];
$code_office = $line[0];
}
// create a child node
$officeNode.$i= $root->new_child("office", "");
// set an attribute to the child node
$officeNode.$i->set_attribute("name", "$officename");
// create a child node and add content
$officeNode.$i->set_attribute("code_office", "$code_office");
$resultstock = get_result_stock($code_office);
$j = 0;
while ($linestock = pg_fetch_array($resultstock))
{
echo " i = ".$i."et cpt ".$cpt." et j = ".$j;
$code_article = $linestock[0];
$start = $linestock[1];
$end = $linestock[2];
$qte=$bstart;
echo "stockNode".$i.$j ;
// $stockNode.$i.$j->set_attribute("code_article",$code_article);
$stockobj = $stockNode.$i.$j ;
$stockNode.$i.$j = $officeNode.$i->new_child("stock", "$qte" );
$stockNode.$i.$j ->set_attribute("code_article","11111");
$j++;
}//end while
$i++;
}
// write to file
$fp = fopen($filename.$filedate.".xml", "w+" );
fwrite($fp, $doc->dumpmem(), strlen($doc->dumpmem() ));
fclose($fp);
// Ferme la connexion
pg_close($pgsql_conn);
}
else
{
echo pg_last_notice($pgsql_conn);
exit;
}
echo "\n fin du programme";
function get_result_stock ($code_office)
{
$stockquery = "SELECT category_id , start , end from stock where op_type='1' and office_id='$code_office'";
$resultstock = pg_exec($stockquery) or die();
return $resultstock ;
}
?> |
Partager