Jump to content
php.lv forumi
Sign in to follow this  
Ernijs_E

MySql uz XML

Recommended Posts

Sveiki,

 

Gribēju jautāt vai nav kaut kāds vienkāršs variants kā no datubāzes izvadīt informāciju un izveidot xml failā?

Share this post


Link to post
Share on other sites

Kur tad vēl vienkāršāk par parastu ciklu un drukāšanu ārā? :)

 

Protams, noteikti eksistē arī gatavi rīki tā darīšanai...

Share this post


Link to post
Share on other sites

Protams, noteikti eksistē arī gatavi rīki tā darīšanai...

Eksistet, jau droši vien eksistē, bet ņemot vērā to ka vienkārša XML faila gadījumā kods sastāv burtiski no pāris desmitu rindiņām, varu iedomāties kāds koda blāķis būs gatavam risinājumam.

Kārtējo reizi: klase lai pieslēgtos DB, klase lai izvadītu no DB, klase lai konfigurētu XML tāgus utt.

---

EDIT:

primitīvā varjantā:

<?php
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
//  ####################
$db=mysql_connect($hosts, $users, $paswords);
mysql_select_db("$dbname");
mysql_query("SET NAMES UTF8");
//  ####################
$query="SELECT a1, a2, a3 FROM tabulis ";
$result= mysql_query($query);
print "<pirmais_taags>\r\n";
while($row=mysql_fetch_array($result)){
 print "<a1_taags>".$row['a1']."</a1_taags>\r\n";
 print "<a2_taags>".$row['a2']."</a2_taags>\r\n";
 print "<a3_taags>".$row['a3']."</a3_taags>\r\n";
}
print "</pirmais_taags>\r\n";
mysql_free_result($result);
?>

Edited by Grey_Wolf

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...