开发者社区> 问答> 正文

警告:mysql_fetch_array():提供的参数不是有效的MySQL结果

尝试运行此命令时出现错误:

query('SELECT title,content FROM staff_vacancies ORDER BY ordering LIMIT 0,100'); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo $row['title'].''; echo $row['content']; } ?> 我有一个链接文件:DbConnector.php: link = mysql_connect($host, $user, $pass); mysql_select_db($db); register_shutdown_function(array(&$this, 'close')); } //*** Function: query, Purpose: Execute a database query *** function query($query) { $this->theQuery = $query; return mysql_query($query, $this->link); } //*** Function: getQuery, Purpose: Returns the last database query, for debugging *** function getQuery() { return $this->theQuery; } //*** Function: getNumRows, Purpose: Return row count, MySQL version *** function getNumRows($result) { return mysql_num_rows($result); } //*** Function: fetchArray, Purpose: Get array of query results *** function fetchArray($result) { return mysql_fetch_array($result); } //*** Function: close, Purpose: Close the connection *** function close() { mysql_close($this->link); } } ?> 有人知道问题出在哪里吗?

展开
收起
保持可爱mmm 2020-05-08 10:56:58 611 0
1 条回答
写回答
取消 提交回答
  • 您的查询必须存在一个导致$ result无效的资源的问题。

    尝试在运行查询的行之后检查mysql_error()。

    编辑:

    实际上,我会将您的DBConnector类函数query()更改为以下内容,以便在查询错误时抛出可识别的错误:

    function query($query) { $this->theQuery = $query; $queryId = mysql_query($query,$this->link); if (! $queryId) { throw new Exception(mysql_error().". Query was:\n\n".$query."\n\nError number: ".mysql_errno(); } return $queryId; }来源:stack overflow

    2020-05-08 10:57:11
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像