我有两个错误,我找不到任何方法来解决它们
警告:mysqli_query期望至少有2个参数,1个给出
查询错误:SELECT ID
,TITLE
,CONTENT
,AUTHOR
,DATE
FROM NEWS
ORDER BY ID
DESC。
<?php
include("site.inc.php");
db_login();
//Generate the query so we can retrieve all titles in the DB in descending ID order
$query = 'SELECT `id`, `title`, `content`, `author`, `date` FROM `news` ORDER BY `id` DESC';
$result = mysqli_query($query)
or die ("Error in query: $query. " . mysqli_connect_error());
// if records are present
if (mysql_num_rows($result) > 0) {
while($send = mysql_fetch_object($result)) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<?php
echo"$send->content";
?>
</td>
</tr>
<tr>
<?Php
echo "$send->author";
}
}
?>
</tr>
<br>
</table>
function db_login
<?php
$confg['db_uname'] = "root";
$confg['db_paswd'] = "";
$confg['db_host'] = "localhost";
$confg['db_dbase'] = "dbname";
function db_login() {
global $confg;
$link = @mysqli_connect($confg['db_host'], $confg['db_uname'], $confg['db_paswd']) or die("Error connecting: " . mysql_error());
@mysqli_select_db($confg['db_dbase'], $link);
mysqli_query($link,"set names 'utf8';");
}
function db_logout() {
@mysqli_close($link);
}
?>
答案 0 :(得分:0)
添加指向执行
的链接 $result = mysqli_query($link, $query)
or die ("Error in query: $query. " . mysqli_connect_error());
答案 1 :(得分:0)
您需要在使用mysqli_query()
时传递连接字符串。
您的查询应如下所示:
$query = 'SELECT `id`, `title`, `content`, `author`, `date` FROM `news` ORDER BY `id` DESC';
$result = mysqli_query($link, $query) or die ("Error in query: $query. " . mysqli_connect_error());