繁体   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