1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. To combat forum spam, new accounts will need to make at least one (valid) post.
    Otherwise, we will periodically purge all users without posts or that haven't confirmed their account.

Creating a XML File

Discussion in 'General Support' started by kennyweb, Oct 10, 2006.

Thread Status:
Not open for further replies.
  1. kennyweb

    kennyweb New Member

    FYI - have created a script to export data base to XML file
    Hope this can be helpful to someone else.
    :banana:

    <?php
    // example of connection to a database
    $hostname ="remotemysqlhost";
    $username ="kenn3_caldlma";
    $password ="paswrd";
    $dbName = "kenn3_dlmcal";

    $conn = mysql_connect($hostname,$username,$password);
    mysql_select_db($dbName) or die("Could Not Connect To Database");

    // example of querying your table
    $query = "select id, startDate, endDate, title, descr, category from epc_calendar";

    // example of getting results from query
    $result = mysql_query($query,$conn);
    if($result) {
    // if query ran successfully
    // loop over results
    //open file to write to
    $file_handle = fopen('events.xml','w');

    // i normal remove this this line
    $xmlPacket = "<?xml version='1.0'?>\n";


    //----
    $xmlPacket .="<newsblock>\n";

    while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
    // build xml to a variable
    $xmlPacket .=
    "\n<news>
    <active>YES</active>
    <id>".$row['id']."</id>
    <startdate>".$row['startDate']."</startdate>
    <enddate>".$row['endDate']."</enddate>
    <title>".$row['title']."</title>
    <descr>".$row['descr']."</descr>
    <category>".$row['category']."</category>
    </news> \n";
    }
    $xmlPacket .= '</newsblock>';
    }
    else{
    // you probably want to remove this when you are putting this code live.
    die('query failed' . mysql_error());

    // you can replace it with this:
    // which will just build an empty packet rather than killing the process
    $xmlPacket = "<?xml version='1.0'?><calendar></calendar>";
    }
    // write var to file
    fwrite($file_handle,$xmlPacket);
    fclose($file_handle);
    die('Done....');
    ?>
     
  2. Brian

    Brian EPC Developer Staff Member

    Thanks for sharing. :)

    [Makes into a Sticky]
     
  3. muskiediver

    muskiediver New Member

    How can you turn this around to import?

    We create a word document with calendar events, then manually put them one by one into our online calendar. How can you make our word document into an xml file to upload into PHP calendar?
     
  4. JerryDi

    JerryDi New Member

  5. sobe_punk

    sobe_punk New Member

    post your code and i will see if i can offer you any insight into your possible problem if you have yet to figure it out.

    I have aquestion myself though... I have ZERO experience with .ics(iCal) filetypes and am looking for a method of querying the DB as it was successfully accomplished by the above script(thanks by the way) and parsing that info into a useable .ics file stored on my server which is the external feed to the (another) Calendar I also use. Anyone have any ideas?

    Although it would be very nice, I'm not overly concerned with a 2-way sync, but instead just getting the feed to my (another) Calendar, in turn having it transmitted(auto synced which is already accomplished) to my BlackBerry.
     
    Last edited by a moderator: Apr 26, 2008
Thread Status:
Not open for further replies.

Share This Page