如以下代码:
<?php
$result = mysql_query("select count(*) from exampletable;");
$row = mysql_fetch_array($result);
if(empty($row[0]))
{
echo "没有内容";
}
?>
<?php
$result = mysql_query("select count(*) from exampletable;");
$row = mysql_fetch_array($result);
if(empty($row[0]))
{
echo "没有内容";
}
?>
$result=pdo::query(.......);
if(!$result->rowCount()) ...........
<?php
mysql_connect("localhost","root","root");//连接数据库软件
mysql_select_db("example");//选择数据库
$result=mysql_query("select count(*) from exampletable;");//执行SQL查询,但不是返回内容,而是返回内容的数量(返回全部内容很浪费资源)返回的是数字
$row=mysql_fetch_array($result);//查询结果
if(empty($row[0]))//判断
{
echo "没有内容";
}
else
{
echo "有内容";
}?>
<?php
$dbh = new PDO('mysql:host=localhost;dbname=database','root','');//PDO方式连接数据库软件
$res=$dbh->query("select count(*) from table;");//PDO方式执行SQL查询,但不是返回内容,而是返回内容的数量(返回全部内容很浪费资源),返回的是资源变量
$row=$res->fetch(PDO::FETCH_BOTH);//PDO处理结果集
if(empty($row[0]))//判断
{
echo "没有内容";
}
else
{
echo "有内容";
}
?>
测试过,可行的
$query = $dbh->prepare($sql);
$query->execute(array(':devid'=>$_POST['devid']));
$row = $query->fetch(PDO::FETCH_ASSOC);