2017-02-06 107 views
-1

我有這兩個錯誤我找不到任何辦法來解決這些問題mysqli_query預計至少2個參數

警告:mysqli_query預計至少2個參數,1只給予在

錯誤查詢:SELECT ID,TITLE, CONTENT,AUTHOR,DATE FROM NEWS ORDER BY ID DESC。

screenshoot from the error

<?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> 

功能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); 

} 

?> 
+1

'mysqli_query($查詢)'=>'mysqli_query($連接,$查詢)' – Qirel

+1

正如錯誤狀態。所以,RTM http://php.net/manual/en/mysqli.query.php - 你真的應該有谷歌的錯誤,並在發佈之前閱讀手冊。 –

+0

我google'd錯誤,我沒有找到解決方案 – Bacha

回答

0

添加鏈接到你的執行

$result = mysqli_query($link, $query) 
     or die ("Error in query: $query. " . mysqli_connect_error()); 
+0

當我添加鏈接:UNDEFINED VARIABLE鏈接之前發出警告 – Bacha

+0

U需要返回$鏈接在您的函數db_login和更改後db_login();到$ link = db_login(); –

+0

Juste認爲:在db_login()的末尾添加「return $ link」並更改「db_login();」到「$ link = db_login();」在你的主文件 –

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()); 
+0

當我添加鏈接:UNDEFINED VARIABLE鏈接之前警告 – Bacha

+0

返回函數'db_login()'的連接字符串。 –

相關問題