教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php 提示Warning: mysql_fetch_array() expects

php 提示Warning: mysql_fetch_array() expects

发布时间:2018-10-16   编辑:jiaochengji.com
教程集为您提供php 提示Warning: mysql,fetch,array() expects等资源,欢迎您收藏本站,我们将为您提供最新的php 提示Warning: mysql,fetch,array() expects资源
在mysql数据库连接时碰到Warning: mysql_fetch_array() expects ...错误提示,根据我的经验这个是sql返回的query为空了,我们没有加己判断直接使用了mysql_fetch_array()函数导致的下面我们一起来看问题解决方案。

我的高度代码如下

include("conn.php");

if(!empty($_GET['id'])){
         $sql="select * from news where `id`='".$_GET['id']."'";
         $query=mysql_query($sql);
         $rs = mysql_fetch_array($query);     
}

提示错误了

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in F:xmappwww.111cn.netmylibrarysearch_result.php on line 32

后来我对代码进行升级

if(!empty($_GET['id'])){
         $sql="select * from news where `id`='".$_GET['id']."'";
         $query=mysql_query($sql);
if( mysql_num_rows( $query )
{
         $rs = mysql_fetch_array($query);  
}
else
{
mysql_error();
}  
}

这样就会看到mysql错误信息了,结果是sql语句有问题了,把sql语句进行修改就可以了,

一聚教程小编提示你,导致这类错误是我们语法不规范了,如果要处理只有对sql进行一条条输出处理或在mysql_query(sql) or die(mysql_error()) 这样来处理 本站原创转载必须注明来源http://www.111cn.net/phper/php.html 

您可能感兴趣的文章:
php 提示Warning: mysql_fetch_array() expects
Warning: mysql_fetch_assoc() expects parameter 1 to be resource解决方法
php number_format函数怎么用?
php不显示warning方法
php应用mktime获取时间戳的例子分析
Warning: mysql_fetch_array():
PHP出现Warning: scandir()问题的解决方法
php无法选择数据库
php提示Warning: file_get_contents(): couldn’t resolve
php多键值cookie操作的例子

[关闭]
~ ~