开发者社区> 问答> 正文

升级PHP7后,PHP脚本无法正常工作

我们的服务器已从PHP5.x升级到PHP7.2。大多数脚本都能按预期工作,但是这个脚本(从phpBB论坛获取最新的论坛帖子)给我们带来了麻烦。以前的代码是:


//Path to the forum config.php file
include "***********";

//Forum address, without dash at the end

$forum_address = "*********";

//Number of the latest topics

$latest = 12;

$link = $link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd");

if (!$link)

{

   die('Not connected : ' . mysql_error());

}

$db_selected = mysql_select_db("$dbname", $link);

if (!$db_selected)

{

   die ('Can\'t use foo : ' . mysql_error());

}

mysql_query("SET NAMES iso-8859-1");

$get_url = "SELECT config_name, config_value FROM $table_prefix".'config'." WHERE config_name = 'server_name' LIMIT 0,1";

$url = mysql_query($get_url);

$url = mysql_fetch_array($url);
$latest_topics;
//to add excluded forum add "AND forum_id<>$id_to_the_forum" after "topic_approved = '1'"
$latest_topics = "SELECT * FROM $table_prefix".'topics'." WHERE topic_approved = '1' AND forum_id<>12 ORDER BY topic_last_post_time DESC LIMIT 0,$latest";

$topics = mysql_query($latest_topics);

while($row = mysql_fetch_array($topics))
{
   extract($row);
   $date = date("d.m.Y", $topic_last_post_time);
?>
   <div style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:24px;"> <a href="//www.flatpanels.dk/flatforum/viewtopic.php?f=<?= $forum_id ?>&t=<?= $topic_id ?>&view=unread#unreads" target="_parent" title="<?= $topic_title ?>" style="color:#666;text-decoration:none;">

<div class="visible-lg-inline visible-xs-inline">   <?
$position=35; // Define how many character you want to display.

$post = substr($topic_title , 0, $position); 

echo $post;

?></div>

<div class="visible-md-inline hidden-xs"> <?
$position=28; // Define how many character you want to display.

$post = substr($topic_title , 0, $position); 

echo $post;

?>

</div>

</a> <span style="font-size:14px;color: #999;display:inline;" />(<?= $topic_replies ?>)</span /></div>
<?php
}
?>

由于我的PHP技能非常有限,我试图修改短打开标记并将mysql更改为mysqli。但是,它仍然无法正常工作。它具有与数据库的连接,但未输出。这就是我现在所在的位置:


//Path to the forum config.php file
include "************";

//Forum address, without dash at the end

$forum_address = "**********";

//Number of the latest topics

$latest = 12;

$link = $link = mysqli_connect("$dbhost", "$dbuser", "$dbpasswd");

if (!$link)

{

   die('Not connected : ' . mysqli_error());

}

$db_selected = mysqli_select_db($link, "$dbname");

if (!$db_selected)

{

   die ('Can\'t use foo : ' . mysqli_error());

}

mysqli_query("SET NAMES iso-8859-1");

$get_url = "SELECT config_name, config_value FROM $table_prefix".'config'." WHERE config_name = 'server_name' LIMIT 0,1";

$url = mysqli_query($get_url);

$url = mysqli_fetch_array($url);
$latest_topics;
//to add excluded forum add "AND forum_id<>$id_to_the_forum" after "topic_approved = '1'"
$latest_topics = "SELECT * FROM $table_prefix".'topics'." WHERE topic_approved = '1' AND forum_id<>12 ORDER BY topic_last_post_time DESC LIMIT 0,$latest";

$topics = mysqli_query($latest_topics);

while($row = mysqli_fetch_array($topics))
{
   extract($row);
   $date = date("d.m.Y", $topic_last_post_time);
?>
   <div style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:24px;"> <a href="//www.flatpanels.dk/flatforum/viewtopic.php?f=<?php echo $forum_id ?>&t=<?php echo $topic_id ?>&view=unread#unread" target="_parent" title="<?php echo $topic_title ?>" style="color:#666;text-decoration:none;">

<div class="visible-lg-inline">   <?php
$position=35; // Define how many character you want to display.

$post = substr($topic_title , 0, $position); 

echo $post;

?></div>

<div class="visible-md-inline hidden-xs"> <?php
$position=28; // Define how many character you want to display.

$post = substr($topic_title , 0, $position); 

echo $post;

?>

</div>

</a> <span style="font-size:14px;color: #999;display:inline;" />(<?php echo $topic_replies ?>)</span /></div>
<?php
}
?>

展开
收起
社区秘书 2019-11-19 14:28:11 1048 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载
复杂PHP系统性能瓶颈排查及优化 立即下载