Load XmlFile from a mysql database.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wsdcent
    New Member
    • Mar 2008
    • 1

    Load XmlFile from a mysql database.

    Hi every one. I'm trying to read a xml file dynamically from mysql database .
    There is my actual code:
    It only works if the file is a local file or if is an absolute path. Whenever i try to load the $PAD variable from a database is always return an error. Can you guys help me with this???

    [code=php]
    <?php require_once('. ./../Connections/xml.php'); ?>
    <?php
    if (!function_exis ts("GetSQLValue String")) {
    function GetSQLValueStri ng($theValue, $theType, $theDefinedValu e = "", $theNotDefinedV alue = "")
    {
    $theValue = get_magic_quote s_gpc() ? stripslashes($t heValue) : $theValue;

    $theValue = function_exists ("mysql_real_es cape_string") ? mysql_real_esca pe_string($theV alue) : mysql_escape_st ring($theValue) ;

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValu e) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theV alue) . "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValu e : $theNotDefinedV alue;
    break;
    }
    return $theValue;
    }
    }

    mysql_select_db ($database_xml, $xml);
    $query_xmldat = "SELECT * FROM uno WHERE id = 1";
    $xmldat = mysql_query($qu ery_xmldat, $xml) or die(mysql_error ());
    $row_xmldat = mysql_fetch_ass oc($xmldat);
    $totalRows_xmld at = mysql_num_rows( $xmldat);


    // Includes
    include_once(". ./include/padfile.php");

    // Create PAD file object for the local file "pad_file.x ml"
    // This could also be an absolute local path or an URL!
    $PAD = new PADFile("./samples/pad_file.xml");

    // Load file
    if ( !$PAD->Load() )
    echo "Error: Cannot load PAD file.<br>\n";

    // Sample Output
    echo "<b>Program Name:</b> " . $PAD->XML->GetValue("XML_ DIZ_INFO/Program_Info/Program_Name") . "<br>\n";
    echo "<b>Program Version:</b> " . $PAD->XML->GetValue("XML_ DIZ_INFO/Program_Info/Program_Version ") . "<br>\n";


    mysql_free_resu lt($xmldat);
    ?>
    [/code]
    Last edited by jkmyoung; Mar 24 '08, 06:05 PM. Reason: code tags
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    If you are new to using forms you may want to google rules on proper form etiquette. It will help you get much better responses.

    Specifically :
    1. Questions about PHP and or SQL would be better off in a form for PHP and or SQL.

    2. Just saying it does not work does not tell any one much. What happens? Getting a null value, an error, etc.

    3. When providing source code for help it is better to post the code the that is acutally failing. That looks like the code that you where loading the XML from a file with. If your question relates to loading it from a data base then that is the example code that should be provided.


    I do not know PHP, but it looks like your problem may relate to your SQL query. Unless your database API includes a function that converts the result set to an XML object then you are probably trying to pass straight text to and XML defined object.

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      Whenever i try to load the $PAD variable from a database is always return an error. Can you guys help me with this???
      Could you show the code where you try to load the variable from a database? It may be a casting problem, or similar problem.

      Comment

      Working...