0

I'm trying to run a simple MySQl procedure in XML format then call it through PHP. This is my SQL procedure:

Select *
from sessionlogs
order by sessionID desc, eventID asc
LIMIT 10;

This is my PHP code:

<?php


// Create connection
$conn = new mysqli('localhost', 'root', 'secret', 'edgeserver');

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

// Perform queries 
$result = mysqli_query($conn, 
    "call new_session") or die("Query fail: " . mysqli_error($conn));

  //loop the result set
while ($row = mysqli_fetch_array($result)){   
     echo $row[0] . " " . + $row[1]; 
  }

$conn->close();

?>

Cant seem to get it into XML format. Please Help.

Dobro
  • 41
  • 4
  • Isnt that a SQL statement that you have given? Certainly does not look like a procedure to me. Have a look at this. https://dev.mysql.com/doc/refman/5.1/en/xml-functions.html – aksappy May 19 '15 at 06:30
  • Yes I've missed put the create procedure, BEGIN and END but it executes fine within MySQL. – Dobro May 19 '15 at 06:51
  • What have you tried to turn the query output into XML? And what is the XML format you want to produce? You need to at least provide an example of the expected XML output. – har07 May 19 '15 at 06:55
  • Yes I did this with the FOR XML function in MSSQL. It's very long so I cant send it. Is there any functions similar to FOR XML in MySQL? – Dobro May 19 '15 at 08:05
  • @Dobro AFAIK, MySQL doesn't have something like MSSQL's `FOR XML` : http://stackoverflow.com/questions/7623308/does-mysql-have-xml-support-like-sql-server . You can generate XML output from query through it's command line tool : http://dev.mysql.com/doc/refman/5.1/en/mysql-command-options.html#option_mysql_xml – har07 May 19 '15 at 08:25
  • Sorry I'm a real beginner. So there's no way to execute a command in PHP either that will convert the output to XML? – Dobro May 19 '15 at 08:59
  • @Dobro: Please see the duplicate question and let me know if this is what you're looking for. – hakre May 19 '15 at 21:57
  • Thanks for the link it's actually helped me with a couple of other things. This is not a duplicate answer though. I was asking how to execute a stored procedure not a simple select statement. Please advise. Thanks. – Dobro May 22 '15 at 06:06

0 Answers0