Home >Backend Development >PHP Tutorial >php empty函数判断mysql表单是否为空_PHP

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

WBOY
WBOYOriginal
2016-06-01 12:19:511154browse

值来进行判断。
很简单的,给一个例子。
方法一:
复制代码 代码如下:
$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变会终止执行。

Statement:
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