Table of Contents
php提示Warning:mysql_fetch_array() expects的解决方法,expects
Home php教程 php手册 php提示Warning:mysql_fetch_array() expects的解决方法,expects

php提示Warning:mysql_fetch_array() expects的解决方法,expects

Jun 13, 2016 am 09:18 AM
mysql php Solution

php提示Warning:mysql_fetch_array() expects的解决方法,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:xmappmylibrarysearch_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()) 这样来处理,以便更准确的定位错误。

希望本文所述对大家的PHP程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

The Python subprocess module fails to execute the wmic datafile command. How to solve it? The Python subprocess module fails to execute the wmic datafile command. How to solve it? Apr 01, 2025 pm 08:48 PM

Use Python's subprocess module to execute wmic...

When using Django and MySQL to process hundreds of thousands to one or two million pieces of data, what kind of cache solution should a 4-core 8G memory server choose? When using Django and MySQL to process hundreds of thousands to one or two million pieces of data, what kind of cache solution should a 4-core 8G memory server choose? Apr 01, 2025 pm 11:36 PM

Using Django and MySQL to process large data volumes When using Django and MySQL databases, if your data volume reaches hundreds of thousands to one or two million...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Python 3.6 loading pickle file error ModuleNotFoundError: What should I do if I load pickle file '__builtin__'? Python 3.6 loading pickle file error ModuleNotFoundError: What should I do if I load pickle file '__builtin__'? Apr 02, 2025 am 06:27 AM

Loading pickle file in Python 3.6 environment error: ModuleNotFoundError:Nomodulenamed...

Where to download Python .whl files under Windows? Where to download Python .whl files under Windows? Apr 01, 2025 pm 08:18 PM

Python binary library (.whl) download method explores the difficulties many Python developers encounter when installing certain libraries on Windows systems. A common solution...

See all articles