php 判断查询结果是否为空

select count(people) c from people where people='乐乐'

上面这条sql就是原理

php利用代码

 

<?php 
$p=$_POST['p'];
$cnx = new PDO("odbc:Driver={SQL Server};Server=;Database=;",'','');
$ps=$cnx->query("select count(people) c from people where people='".$p."'");
foreach($ps as $s){
if ($s['c']=='0'){
echo "用户可用";
}else{
echo "此用户名已存在";
}

} 
?>

 

  

posted @ 2014-12-25 11:44  fleam  阅读(1296)  评论(0编辑  收藏  举报