Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Display MySQL Query Result from JIRA DB in Confluence Page?

Cole
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2017

I am trying to display results from a MySQL query to the JIRA Database using an HTML macro. The script I put in looked like it should work, however, it doesn't show anything. The page is completely blank. What am i doing wrong?

 

<script>
<?php
$con=mysqli_connect("example.com","user","pass","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM cwd_user");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['first_name'] . "</td>";
echo "<td>" . $row['last_name'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>
</script>

2 answers

0 votes
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2017

PHP is a server side language. HTML is client side. You can only put HTML into the HTML macro. If you want to display the results of a SQL query on a Confluence page you should look into a SQL add-on from the marketplace. Another option would be to host your PHP elsewhere and then in the HTML macro do an AJAX call to the PHP page and insert the data into the Confluence page. Confluence has jQuery, so it wouldn't be too hard to setup the AJAX.

Cole
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2017

Unfortunately, I am unable to purchase any add-ons. I will look into your other suggestion, but I am not too sure how to execute it. I wish it were easier to pull data from the JIRA database.

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2017

Another option would be to implement you php page elsewhere and then iframe it into Confluence.

0 votes
Julian Riedinger [Decadis AG]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2017

Hi Cole,

as far as I know, you are not able to write php-code within a macro. Maybe you have a look on this add-on?

 

https://marketplace.atlassian.com/plugins/de.scandio.confluence.plugins.pocketquery/server/pricing

 

Cheers,

Julian

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events