Home  >  Article  >  Backend Development  >  How to determine whether the query result is empty in php

How to determine whether the query result is empty in php

coldplay.xixi
coldplay.xixiOriginal
2020-09-04 10:17:374781browse

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'];].

How to determine whether the query result is empty in php

[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[&#39;p&#39;];
$cnx = new PDO("odbc:Driver={SQL Server};Server=;Database=;",&#39;&#39;,&#39;&#39;);
$ps=$cnx->query("select count(people) c from people where people=&#39;".$p."&#39;");
foreach($ps as $s){
if ($s[&#39;c&#39;]==&#39;0&#39;){
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!

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