Home > Article > Backend Development > How to determine whether the query result is empty in php
php method to determine whether the query result is empty: 1. Use the sql method, the code is [select count(people) c from people where people='Lele']; 2. Use the php method, the code is [$p=$_POST['p'];].
[Related learning recommendations: php programming (video)]
php method to determine whether the query result is empty:
1,
select count(people) c from people where people='乐乐'
The above sql is the principle
2,
php utilization code
<?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 "此用户名已存在"; } } ?>
If you want to learn more about programming, please pay attention to the php training column!
The above is the detailed content of How to determine whether the query result is empty in php. For more information, please follow other related articles on the PHP Chinese website!