SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    Gold Coast
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML MYSQL and PHP

    consider this php file.

    <?php
    $sourcefile = fopen('docbook.xml', 'r');
    $xml = fread($sourcefile, filesize('docbook.xml'));
    fclose($sourcefile);

    $xslfile = fopen('docbook.xsl', 'r');
    $xsl = fread($xslfile, filesize('docbook.xsl'));
    fclose($xslfile);

    $ok = xslt_process($xsl, $xml, $html);
    if (!$ok) die("XSLT processing error: ".xslt_error());

    echo $html;
    ?>

    How can i pull xml data straight from a datbase table, I have tried to do it with PHP with no success?

    Thanks if you can help,

  2. #2
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    597
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe i can help.
    can you explain what exactly you are trying to accomplish? if you have data in a database and would like it returned as an xml document (having the rdbms doing all the work) that would be different than writing a loop to insert all the tags after extracting all data from the db.


    dlg

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    Gold Coast
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what i was trying to do was create the xml document with php.

    I gave up trying to do that and instead pulled the already xml structured data into a variable and then applied the xsl to it as in the code above.

    that would be different than writing a loop to insert all the tags after extracting all data from the db.
    Im not sure i understand what you mean here.
    please explain a scenario this would be practicle

  4. #4
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    597
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you know how to connect to a dB, query, and print the results?

    shouldn't be more than:
    Code:
    <?php
    $connection = mysql_connect("localhost", "DB", "PASSWORD") or die ("Couldn't connect to the server.");
    $db 		= mysql_select_db("HOST_com", $connection) or die ("Couldn't select database.");
    $sql            = "SELECT xmlData* FROM databaseTable WHERE LoanAcctNo = 12365";
    $sql_result     = mysql_query($sql, $connection) or die("Couldn't query Speedpay_Main table.");
    			while ($row = mysql_fetch_array($sql_result)){
    				$xmlDoc	=	$row["xmlData"];
    }
    
    echo $xmlDoc
    
    ?>

  5. #5
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    597
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but if you put all of your XML into a database then this would inhibit variables to be used within your xml.

    loop
    <xml tags>
    <xml tags>
    $variable
    </xml tags>
    </xml tags>
    end loop
    <xml tag>
    <xml tag> $variable2</xml tag>
    </xml tag>


    etc.

    know what i mean?

  6. #6
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Storing the XML in the database doesn't stop you from using variables if you want too, you just need to use eval() on the XML from the database. You can also use loops etc. inside the XML from the database, but that requires a bit more coding and work using eval().

    It can certainly be done as I have just finished v2 of a project that uses a similar system to what you are trying to develop, v1 didn't use XML, but did have the templates stored in the database and did use variables etc. in the templates. v2 added XML + XSL formatting of data, a page cache system and designing a formatting language for articles etc.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  7. #7
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    597
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please demonstrate the eval() is this a sort of "search & replace" function?

    the dB that you stored your XML, is it oracle or sqlserver 2k? could you do that with mySQL?

    i would love to learn more about v1 and v2 of your project, as I am always "ears" about learning more practical applications using xml.

    dlg

  8. #8
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used mySQL in this instance, but it will be ported to PostgreSQL very soon.

    eval does what it says, it evaluates a string as PHP would do. e.g.
    PHP Code:
    <?php

     $var1 
    'Karl';
     
    $var2 'My name is $var1';

     echo 
    $var2.'<br />';
     eval(
    '$var3 = "'.$var2.'";');
     echo 
    $var3;

    ?>
    This would print:

    My name is $var1
    My name is Karl

    I hope this helps.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.


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
  •