所以我在数据库中输入了一些引号,我想把它显示在phpbb3论坛页面的页脚块上。
我为数据库连接和查询创建了一个名为"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");
?>
在页脚块上,我添加了以下行:
<div id="col1">
<!-- Column one content beginning -->
<!-- INCLUDEPHP http://pallet-town.net/backend/ligacao.php -->
<!-- PHP -->
echo $tipQuery;
<!-- ENDPHP -->
<!-- Column one content end -->
</div>
mysql在同一服务器上,但phpbb没有在任何其他实例中使用它
该查询运行良好,因为我在使用前对其进行了测试。
到目前为止,结果是一个空的页脚块
我已经在acp上启用了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");
?>
<div id="col1">
<!-- Column one content beginning -->
<!-- INCLUDEPHP http://pallet-town.net/backend/ligacao.php -->
<!-- PHP -->
while ($obj=$ligacao->fetch_object($tipQuery))
{
printf("%s n",$obj->tipQuote);
}
<!-- ENDPHP -->
<!-- Column one content end -->
</div>
在回显查询结果之前,您错过了一个步骤。这样试试:
<?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");
$obj = $ligacao->fetch_object($tipQuery);
?>
<div id="col1">
<!-- Column one content beginning -->
<!-- INCLUDEPHP http://pallet-town.net/backend/ligacao.php -->
<!-- PHP -->
echo $obj->tipQuote;
<!-- ENDPHP -->
<!-- Column one content end -->
</div>
如果其他人也有同样的问题,我最终找到了答案:
$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);
因此,为了访问外部mysql,您需要论坛根文件夹上的一个PHP文件。要在代码中包含,只需将<!-- INCLUDEPHP YOUR-FILE.php -->
添加到要插入信息的位置即可。
在这种特殊情况下,最终的php文件代码是:
<?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);
?>