So i entered few quotes on a database and i wanted to display it on a footer block of my phpbb3 forums page.
I created a file for the database connection and query called "ligacao.php":
<?php
$ligacao = new mysqli("localhost","starwmjz_mike","PASSWORD","starwmjz_pallet");
if($ligacao->connect_error){
die("Error:" . $ligacao->connect_errno . "," . $ligacao->connect_error);
}
$ligacao->set_charset("utf8");
$tipQuery = $ligacao->query("SELECT tipQuote FROM tips ORDER BY rand() limit 1");
?>
And on the footer block i added these lines:
<div id="col1">
<!-- Column one content beginning -->
<!-- INCLUDEPHP http://pallet-town.net/backend/ligacao.php -->
<!-- PHP -->
echo $tipQuery;
<!-- ENDPHP -->
<!-- Column one content end -->
</div>
The mysql is on the same server but its not being using by phpbb in any other instance
The query works just fine as i tested it before using it.
The result is an empty footer block so far.
I've enabled php on the acp.
All help and suggestions are welcome, Thanks.
I eventually found the answer, if anyone else has the same problem this worked for me:
$result = mysqli_query($ligacao,"SELECT * FROM YOUR-TABLE-NAMe ORDER BY rand() LIMIT 1");
while($row = mysqli_fetch_array($result)) {
echo $row['YOUR-ROW-NAME'];
}
mysqli_close($ligacao);
So in order to access an exterior mysql you need a single PHP file on the root folder of the forums.
To include in on your code, just add <!-- INCLUDEPHP YOUR-FILE.php -->
to where you'll want the the information to be inserted.
In this particular case the final php file code is:
<?php
$ligacao = new mysqli("YOUR-HOST","DATABASE-USER","PASSWORD","DATABASE-NAME");
if($ligacao->connect_error){
die("Error:" . $ligacao->connect_errno . "," . $ligacao->connect_error);
}
$ligacao->set_charset("utf8");
$result = mysqli_query($ligacao,"SELECT * FROM YOUR-TABLE-NAME ORDER BY rand() LIMIT 1");
while($row = mysqli_fetch_array($result)) {
echo $row['YOUR-ROW-NAME'];
}
mysqli_close($ligacao);
?>