簡體   English   中英

使用未定義的常量mysql_error - 假設為'mysql_error

[英]Use of undefined constant mysql_error - assumed 'mysql_error

我正在嘗試使用數據庫檢索數據,但將其限制為每個視圖的特定數量的項目。 但相反,我得到了上面提到的錯誤。 我創建了以下函數來檢索數據:

//function to display jobs
function display_jobs($start,$per_page)
{
    //Select the data from the database, but limit it to the number of item per page
    $query = "SELECT a.`title`, 
                     a.`vacancyid`, 
                     b.`username`, 
                     c.`date`
                FROM holystic.`vacancy` a
          INNER JOIN holystic.`users` b 
                  ON a.`userid` = b.`userid`
          INNER JOIN holystic.`date` c
                  ON a.`vacancyid` = c.`vacancyid`  
              `LIMIT $start, $per_page;";
    $query_set = mysql_query($query) or die(mysql_error);
    return $query_set;
}

當我刪除or die(mysql_error)語句時,我沒有得到任何結果。 當我在MySQL上直接輸入MySQL時,我得到了結果。 請協助

應該die(mysql_error()); ..你錯過了paranthesis。 它是一個函數,但您將其稱為常量。

$query_set = mysql_query($query) or die(mysql_error());
                                                   ^^---- Here

另外,在LIMT關鍵字之前刪除反引號。 [致@Prix信用]

固定代碼..

function display_jobs($start,$per_page)
{
    //Select the data from the database, but limit it to the number of item per page
    $query = "SELECT a.`title`, 
                     a.`vacancyid`, 
                     b.`username`, 
                     c.`date`
                FROM holystic.`vacancy` a
          INNER JOIN holystic.`users` b 
                  ON a.`userid` = b.`userid`
          INNER JOIN holystic.`date` c
                  ON a.`vacancyid` = c.`vacancyid`  
               LIMIT $start, $per_page;";
    $query_set = mysql_query($query) or die(mysql_error());
    return $query_set;
}

PHP 5.5.0 ,不推薦使用此( mysql_* )擴展,將來將刪除。 相反,應該使用MySQLiPDO_MySQL擴展。 切換到PreparedStatements可以更好地抵御SQL注入攻擊!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM