Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2013

    Question Unanswered: PHP Query -> DB2 Results = XML

    So I've been tasked with moving this php script and some other content from MySQL over to DB2, I'm not proficent with PHP and was hoping someone could help me with this bugger. It's giving me some issues.

    Basically what I need this to do is query the db2 database from the sql POST variable. It should then return the results in xml. This script is currently working with MySQL but DB2 seems like another beast all together. Hopefully someone can help.

    $mysql_hostname = *;
    $mysql_user = *;
    $mysql_password = *";
    $mysql_database = *;
    $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong");
    mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");
    // Opens a connection to a mySQL server
    $connection=mysql_connect ($mysql_hostname, $mysql_user, $mysql_password);
    if (!$connection) {
      die("Not connected : " . mysql_error());
    $dom = new DOMDocument("1.0");
    $node = $dom->createElement("rows");
    $parnode = $dom->appendChild($node);
    // Set the active MySQL database
    $db_selected = mysql_select_db($mysql_database, $connection);
    if (!$db_selected) {
      die ('Can\'t use db : ' . mysql_error());
    // Select all the rows in query
    $query = $mysql_sql;
    $result = mysql_query($query);
    if (!$result) {
      die('Invalid query: ' . mysql_error());
    header("Content-type: text/xml");
    // Iterate through the rows, adding XML nodes for each
    while ($row = @mysql_fetch_assoc($result)){
      $node = $dom->createElement("row");
      $newnode = $parnode->appendChild($node);
        for($i = 0; $i < mysql_num_fields($result); $i++)
          $field_info = mysql_fetch_field($result, $i);
          $newnode->setAttribute($field_info->name, $row[$field_info->name]);
    echo $dom->saveXML();

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    So you need to step through each line of code and understand what it means. What each php object, variable or function does. is a useful resource for that.
    Usually porting code from one db to another is relatively trivial, unless your db code uses non standard functions
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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