Fetching Data From MySQL With Ajax In PHP – Info PHP


This article explains fetching data from MySQL with in PHP. To do that you will first create a table and store some data in it for retrieving with and transform the array data from MySQL to XML using a DOM element. will read the data from the MySQL server form of XML data using PHP code. First of all You will create a client-side file use of HTML with and then create a connection with your database in MySQL then create the PHP code.


This is the “index.html” file.

“Content-Type” content=“text/html; charset=utf-8” />



Your records:

“createDiv” />


And this is the “index.php” code and this file will create a XML document.

header(‘Content-type: text/xml’);



$query = “Select * from `data`”;

$result   = mysql_query($query) or die(mysql_error());

$dom_elements = new DOMDocument();

$ddda = $dom_elements->createElement(‘ddda’);


while($r = mysql_fetch_array($result)){

  $id = $dom_elements->createElement(‘id’);

  $idText = $dom_elements->createTextNode($r[‘id’]);


  $books = $dom_elements->createElement(‘books’);

  $booksText = $dom_elements->createTextNode($r[‘books’]);


  $written_by = $dom_elements->createElement(‘written_by’);

  $written_byText = $dom_elements->createTextNode($r[‘written_by’]);


  $book = $dom_elements->createElement(‘book’);






$string = $dom_elements->saveXML();

echo $string;



display data

Article Prepared by Ollala Corp

You might also like More from author

Leave A Reply

Your email address will not be published.