简体   繁体   English

替代此 php 脚本的 mysqli_num_rows

[英]Alternate to mysqli_num_rows for this php script

I know this has been asked a lot but I can't find no other method that does not relate to num_rows I basically want to see if a record a exist in the database in a if else statement and in other words I don't mind using it but for personal complicated reasons I need to stay away from that because it conflicts on other things I want to add down the road.我知道这已经被问了很多,但我找不到与 num_rows 无关的其他方法我基本上想在if else 语句中查看数据库中是否存在一条记录,换句话说我不介意使用它,但出于个人复杂的原因,我需要远离它,因为它与我想添加的其他东西相冲突。 So this is my code example is there another way to do this with out using mysqli_num_rows?所以这是我的代码示例是否有另一种方法可以不使用 mysqli_num_rows 来做到这一点?

<?php
$servername='localhost';
$username='angel';
$password='1234';
$db_name='test';

$connect= new mysqli($servername,$username,$password,$db_name);

$query="SELECT*FROM members WHERE first_name='bob'";

$result= $connect->query($query);

if($result->num_rows >0){
echo 'Exist';
}

else{
    echo 'Does not exist';
}
?>

just to fill in the options pool只是为了填写选项池

$query = "SELECT id FROM members WHERE first_name='bob'";

then check you get an id returned;然后检查您是否收到了返回的 ID; assuming the table has an id column, if not just use another one假设表有一个id列,如果不是只使用另一个

You could issue a separate query where all you do is count the results:您可以发出一个单独的查询,您所做的就是计算结果:

$getCount = "SELECT COUNT(*) AS `MemberCount` FROM members WHERE first_name='bob'";

Then use the results to determine your program's path.然后使用结果来确定程序的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM