数据库连接在PHP7下不起作用[关闭]

问题描述 投票:0回答:1
当使用PHP5托管网站时,以下几行有效,但现在在PHP7下,它们不起作用,我不知道如何使它们起作用。多年来,我显然没有跟上我的PHP编码...

$db = new Database("localhost", "username", "password", "db"); $bodyHtml .= $db->GetMessage("HomePage"); $html = str_replace('$BODY_CONTENTS$', $bodyHtml, $html); print $html;

“主页”是消息表中的字段
php database php-7
1个回答
0
投票
嗯,假设您正在使用MySQL,则可能应该使用MySQLi库(除非您已经在使用MySQLi并且忘记提供代码了)。如果是上述情况;

$db = new mysqli("localhost", "username", "password", "db"); $queryResult = $db->query("SELECT HomePage from messages"); if ($queryResult->num_rows = 1) { // assuming theres only one row while ($row = $queryResult->fetch_assoc()) { // concatenate to string $bodyHtml .= $row['HomePage']; } } // and your original code $html = str_replace('$BODY_CONTENTS$', $bodyHtml, $html); print $html;

可悲的是,我不想测试该代码,因为我不想为重新创建示例而烦恼。因此,我只能说理论上应该可行。
© www.soinside.com 2019 - 2024. All rights reserved.