close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

MySQLI Query Export to XML File

Thread began 5/20/2019 8:40 am by anonymous | Last modified 6/11/2019 8:20 am by Ray Borduin | 1102 views | 9 replies |

anonymous

MySQLI Query Export to XML File

I have a query below and I need to export the data on the page to an XML file. Is it possible to do this with the Dreamweaver Extension?

<?php
$agreements2 = new WA_MySQLi_RS("agreements2",$sdpc_i,0);
$agreements2->setQuery("SELECT *, clause_agreement_type.clause_agreement_typeID as theclause_agreement_typeID, clause_obligation.clause_obligationID as theclause_obligationID, obligations.obligationID as theobligationID, benchmarks.benchmarkID as thebenchmarkID, contract_clauses.clauseID as theclauseID FROM agreement_types left join clause_agreement_type on agreement_types.agreement_typesID = clause_agreement_type.agreement_typesID left join contract_clauses on contract_clauses.clauseID = clause_agreement_type.clauseID left join clause_obligation on clause_obligation.clause_agreement_typeID = clause_agreement_type.clause_agreement_typeID left join obligations on obligations.obligationID = clause_obligation.obligationID left join obligation_benchmark on clause_obligation.clause_obligationID = obligation_benchmark.clause_obligationID left join benchmarks on obligation_benchmark.benchmarkID = benchmarks.benchmarkID WHERE agreement_types.agreement_typesID = ?");
$agreements2->bindParam("i", "".(isset($_GET['agreement_typesID'])?$_GET['agreement_typesID']:"") ."", "-1"); //colname
$agreements2->execute();?>

Sign in to reply to this post

Ray BorduinWebAssist

HTML is just a form of XML... So of course you can create an xml page from a recordset result. Just write the XML code and add values from the database where you want them.

Sign in to reply to this post
Did this help? Tips are appreciated...

anonymous

So I did this and I get XML code for one of the records but, there should be three records. Do you know where I went wrong?

<?php require_once('Connections/sdpc_i.php'); ?>
<?php require_once('webassist/mysqli/rsobj.php'); ?>
<?php require_once('webassist/mysqli/queryobj.php'); ?>
<?php require_once('webassist/mysqli/authentication.php'); ?>
<?php
if ("" == "") {
$RestrictAccess = new WA_MySQLi_Auth();
$RestrictAccess->Action = "restrict";
$RestrictAccess->Name = "sdpc_login";
$RestricAccessRedirect = "error.php";
if (function_exists("rel2abs")) $RestricAccessRedirect = $RestricAccessRedirect?rel2abs($RestricAccessRedirect,dirname(__FILE__)):"";
$RestrictAccess->FailRedirect = $RestricAccessRedirect;
$RestrictAccess->execute();
}?>
<?php
$state = $_GET['state'];
$agreement_typesID = $_GET['agreement_typesID'];
$category = $_GET['category'];
$query = new WA_MySQLi_RS("query",$sdpc_i,0);
$query = "SELECT * from ((SELECT agreement_typesID, agreement_name, state, description, category as thecategory, latest, public, concat('https://sdpc.a4l.org/agreements/',file_pdf) as agreement_file_pdf, concat('https://sdpc.a4l.org/agreements/',file_doc) as agreement_file_doc FROM agreement_types where state = '$state' and agreement_typesID = $agreement_typesID and category = '$category') t1 left join (SELECT * FROM agreement_vendor_types) t8 on (t1.agreement_typesID = t8.agreement_typesID) left join (SELECT * from clause_agreement_type) t2 on (t1.agreement_typesID = t2.agreement_typesID or t2.agreement_type_vendorID = t8.agreement_type_vendorID) left join (SELECT * from contract_clauses) t3 on (t3.clauseID = t2.clauseID) left join (select * from clause_obligation) t4 on (t4.clause_agreement_typeID = t2.clause_agreement_typeID) left join (SELECT * from obligations) t5 on (t5.obligationID = t4.obligationID) left join (SELECT * from obligation_benchmark) t6 on (t4.clause_obligationID = t6.clause_obligationID) left join (SELECT *, benchmarkID as thebenchmarkID from benchmarks) t7 on (t6.benchmarkID = t7.benchmarkID))";
$result = $sdpc_i->query($query);
// Associative array
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
// Free result set
mysqli_free_result($result);
mysqli_close($sdpc_i);
function to_xml(SimpleXMLElement $object, array $row)
{
foreach ($row as $key => $value) {
if (is_array($value)) {
$new_object = $object->addChild($key);
to_xml($new_object, $value);
} else {
// if the key is an integer, it needs text with it to actually work.
if ($key == (int) $key) {
$key = "$key";
}
$object->addChild($key, $value);
}
}
}
$xml = new SimpleXMLElement('<data/>');
to_xml($xml, $row);
print $xml->asXML();
header('Content-Type: application/xml; charset=utf-8');
header('Content-Language: en');
header('Cache-Control: no-store, no-cache, must-revalidate');
header("Content-Length: ".filesize($filename));
header("Date: ".gmdate('D, d M Y H:i:s T'));
?>

Sign in to reply to this post

Ray BorduinWebAssist

php:
<?php

$query 
= new WA_MySQLi_RS("query",$localhost,0);
$query->setQuery("SELECT * from ((SELECT agreement_typesID, agreement_name, state, description, category as thecategory, latest, public, concat('https://sdpc.a4l.org/agreements/',file_pdf) as agreement_file_pdf, concat('https://sdpc.a4l.org/agreements/',file_doc) as agreement_file_doc FROM agreement_types where state = ? and agreement_typesID = ? and category = ?) t1 left join (SELECT * FROM agreement_vendor_types) t8 on (t1.agreement_typesID = t8.agreement_typesID) left join (SELECT * from clause_agreement_type) t2 on (t1.agreement_typesID = t2.agreement_typesID or t2.agreement_type_vendorID = t8.agreement_type_vendorID) left join (SELECT * from contract_clauses) t3 on (t3.clauseID = t2.clauseID) left join (select * from clause_obligation) t4 on (t4.clause_agreement_typeID = t2.clause_agreement_typeID) left join (SELECT * from obligations) t5 on (t5.obligationID = t4.obligationID) left join (SELECT * from obligation_benchmark) t6 on (t4.clause_obligationID = t6.clause_obligationID) left join (SELECT *, benchmarkID as thebenchmarkID from benchmarks) t7 on (t6.benchmarkID = t7.benchmarkID))");
$query->bindParam("i""".($_GET['state'])  ."""-1"); //state
$query->bindParam("i""".($_GET['agreement_typesID']); //agreement_typesID
$query->bindParam("i""".($_GET['category'])  ."""-1"); //category
$query->execute();
?>
<?php
function to_xml(SimpleXMLElement $object, array $row)  {
  foreach (
$row as $key => $value) {
    if (
is_array($value)) {
      
$new_object $object->addChild($key);
      
to_xml($new_object$value);
    } else {
      
// if the key is an integer, it needs text with it to actually work.
      
if ($key == (int) $key) {
        
$key "$key";
      }
      
$object->addChild($key$value);
    }
  }
}
?>
<?php

ob_start
();

while (!
$query->atEnd()) {
  
$xml = new SimpleXMLElement('<data/>');
  
to_xml($xml$query->Results[$query->Index]);
  print 
$xml->asXML();
  
$query->moveNext();
}

$output ob_get_contents();
ob_end_clean();

header('Content-Type: application/xml; charset=utf-8');
header('Content-Language: en');
header('Cache-Control: no-store, no-cache, must-revalidate');
header("Content-Length: ".strlen($output));
header("Date: ".gmdate('D, d M Y H:i:s T'));

echo(
$output);
?>
Sign in to reply to this post
Did this help? Tips are appreciated...

anonymous

Thank you for this. I am still getting this error message:

error on line 7 at column 6: XML declaration allowed only at the start of the document

Here is the code we have:

<?php require_once('Connections/sdpc_i.php'); ?>
<?php require_once('webassist/mysqli/rsobj.php'); ?>
<?php require_once('webassist/mysqli/queryobj.php'); ?>
<?php require_once('webassist/mysqli/authentication.php');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL); ?>
<?php
if ("" == "") {
$RestrictAccess = new WA_MySQLi_Auth();
$RestrictAccess->Action = "restrict";
$RestrictAccess->Name = "sdpc_login";
$RestricAccessRedirect = "error.php";
if (function_exists("rel2abs")) $RestricAccessRedirect = $RestricAccessRedirect?rel2abs($RestricAccessRedirect,dirname(__FILE__)):"";
$RestrictAccess->FailRedirect = $RestricAccessRedirect;
$RestrictAccess->execute();
}?>
<?php
$query = new WA_MySQLi_RS("query",$sdpc_i,0);
$query->setQuery("SELECT * from ((SELECT agreement_typesID, agreement_name, state, description, category as thecategory, latest, public, concat('https://sdpc.a4l.org/agreements/',file_pdf) as agreement_file_pdf, concat('https://sdpc.a4l.org/agreements/',file_doc) as agreement_file_doc FROM agreement_types where state = ? and agreement_typesID = ? and category = ?) t1 left join (SELECT * FROM agreement_vendor_types) t8 on (t1.agreement_typesID = t8.agreement_typesID) left join (SELECT * from clause_agreement_type) t2 on (t1.agreement_typesID = t2.agreement_typesID or t2.agreement_type_vendorID = t8.agreement_type_vendorID) left join (SELECT * from contract_clauses) t3 on (t3.clauseID = t2.clauseID) left join (select * from clause_obligation) t4 on (t4.clause_agreement_typeID = t2.clause_agreement_typeID) left join (SELECT * from obligations) t5 on (t5.obligationID = t4.obligationID) left join (SELECT * from obligation_benchmark) t6 on (t4.clause_obligationID = t6.clause_obligationID) left join (SELECT *, benchmarkID as thebenchmarkID from benchmarks) t7 on (t6.benchmarkID = t7.benchmarkID))");
$query->bindParam("s", "".($_GET['state']) ."", "-1"); //state
$query->bindParam("i", "".($_GET['agreement_typesID']) ."", "-1"); //agreement_typesID
$query->bindParam("s", "".($_GET['category']) ."", "-1"); //category
$query->execute();
?>
<?php
function to_xml(SimpleXMLElement $object, array $row) {
foreach ($row as $key => $value) {
if (is_array($value)) {
$new_object = $object->addChild($key);
to_xml($new_object, $value);
} else {
// if the key is an integer, it needs text with it to actually work.
if ($key == (int) $key) {
$key = "$key";
}
$object->addChild($key, $value);
}
}
}
?>
<?php
ob_start();
while (!$query->atEnd()) {
$xml = new SimpleXMLElement('<data/>');
to_xml($xml, $query->Results[$query->Index]);
print $xml->asXML();
$query->moveNext();
}
$output = ob_get_contents();
ob_end_clean();
header('Content-Type: application/xml; charset=utf-8');
header('Content-Language: en');
header('Cache-Control: no-store, no-cache, must-revalidate');
header("Content-Length: ".strlen($output));
header("Date: ".gmdate('D, d M Y H:i:s T'));
echo($output);
?>

Sign in to reply to this post

Ray BorduinWebAssist

Please attach the page you are working on.

Sign in to reply to this post
Did this help? Tips are appreciated...

anonymous

Here you go. Thanks

Lisa

Attached Files
download_pod.php
Sign in to reply to this post

Ray BorduinWebAssist

This appears to be an issue with your recordset data. Perhaps you have a column named "XML" and it is complaining that you can't have a tag with that name in the middle of your document.

I could debug this for you and get it working, but since the issue is with a hand coded and not supported section of your code I'd have to bill you for an hour of premier support in order to fix it ($100).

If you are interested you can just reply to this thread with FTP information and a URL to view the current page and I'll get it working.

Sign in to reply to this post
Did this help? Tips are appreciated...

anonymous

Actually, the recordset data is fine. Not mention of XML there. It seems to have to do with this code:

<?php
ob_start();
while (!$query->atEnd()) {
$xml = new SimpleXMLElement('<data/>');
to_xml($xml, $query->Results[$query->Index]);
print $xml->asXML();
$query->moveNext();
}
$output = ob_get_contents();
ob_end_clean();
header('Content-Type: application/xml; charset=utf-8');
header('Content-Language: en');
header('Cache-Control: no-store, no-cache, must-revalidate');
header("Content-Length: ".strlen($output));
header("Date: ".gmdate('D, d M Y H:i:s T'));
echo($output);
?>

It is echo or printing the output or XML twice. When I remove one of them I get the XML data correctly but, I am still having the original issue of the data not repeating all records.

Sign in to reply to this post

Ray BorduinWebAssist

I can't effectively debug hand coded sections without direct access to the page for debugging.

I could debug this for you and get it working, but since the issue is with a hand coded and not supported section of your code I'd have to bill you for an hour of premier support in order to fix it ($100).

If you are interested you can just reply to this thread with FTP information and a URL to view the current page and I'll get it working.

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...