Results 1 to 3 of 3

Thread: how to insert xml data into mysql using php ?

  1. #1
    Join Date
    Jan 2008
    Posts
    1

    Default how to insert xml data into mysql using php ?

    I wnat to implement xml into my php script.How to create xml file from php and how to insert into it
    Powered by Yahoo!

  2. #2
    Join Date
    Dec 2008
    Posts
    1

    Default

    hello chakarvarty i have same prblm?but i searched on it and got some solution..but still i have some prblms...if u have solution please tell me,otherwise i tell u,if i got...
    Vivek

  3. #3
    Join Date
    Mar 2009
    Location
    Chennai ,Tnagar
    Posts
    1

    Smile Retrieve Records from Mysql using Php in Xml Format

    Hi Everyone its very simple and easy

    My Table Contains two fields date and text


    My code
    Fetch all rows from mysql database and write the output in xml file

    // Connect to the database
    $mcm_db = mysql_connect("localhost", "root", "");
    mysql_select_db("sample", $mcm_db);

    // Issue the query
    $mcm_query = sprintf("SELECT date, text FROM xmltb" );
    $mcm_result = mysql_query($mcm_query, $mcm_db);

    // Format the query results as XML
    if (mysql_num_rows($mcm_result) > 0) {
    // Assemble the XML code
    $xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
    $xml.="<firsttag>\r\n";
    while (list($date, $text) = mysql_fetch_array($mcm_result)) {
    $formatted_date = $date;
    $formatted_time = $text;
    $xml.= sprintf(" <second date=\"%s\" text=\"%s\">\r\n",
    $formatted_date, $formatted_time);
    $xml.= " </second>\r\n";
    }
    $xml.="</firsttag>";

    // Write the XML code to the file mcm_results.xml
    $file= fopen("mcm_results.xml", "w");
    fwrite($file, $xml);
    fclose($file);

    echo "The XML document has been written - <a href=\"mcm_results.xml\">
    view the XML code.</a>";
    } else {
    echo "Sorry, no matching records found.";
    }
    // Close the database
    mysql_close($mcm_db);

    if its wrong please say the correct one

    Thanx in advance


    Ramanathan.V
    Chennai

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •