Home > php教程 > php手册 > php empty函数判断mysql表单是否为空

php empty函数判断mysql表单是否为空

WBOY
Release: 2016-06-13 12:17:36
Original
1050 people have browsed it

值来进行判断。
很简单的,给一个例子。
方法一:

复制代码 代码如下:


$sql = "select * form abc"
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if(empty($row))//开始判断是够为空
{
echo "null";
}
else
{
echo "not null";
}


方法二:

复制代码 代码如下:


$sql = "select * form abc"
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if(!$row)//开始判断是够为空
{
echo "null";
}
else
{
echo "not null";
}


其实mysql_fetch_array函数在使用的时候如果表是空表的话,就会返回false,这个时候$row自然没有赋

值成功。
记住,千万不敢这样用$row = mysql_fetch_array($result)or die(mysql_error());
如果后面哟or die的话,则程序执行到mysql_fetch_array变会终止执行。
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template