[英]Checking to see if record exist by RecordCount()
I have this function in a while loop and for some reason it says all records are duplicates. 我在while循环中有此功能,由于某种原因,它说所有记录都是重复的。
I have tried: 我努力了:
$tst->RecordCount() === 1
$tst->RecordCount() == 1
$tst->RecordCount() = 1
$tst->RecordCount() === '1'
$tst->RecordCount() == '1'
$tst->RecordCount() = '1'
$tst->RecordCount() === "1"
$tst->RecordCount() == "1"
$tst->RecordCount() = "1"
But none seem to work 但似乎没有任何作用
$sql45 = "SELECT
count(*)
FROM
companies
WHERE
MC = " . $test;
$tst = $conn->Execute($sql45);
if ($tst === false) die("horrible death:" . $conn->ErrorMsg() . " SQL: " . $sql45);
if($tst->RecordCount() === 1){
echo $test . "<br>";
echo "Duplicate record <br>";
continue;
}
this is what i recieve 这就是我收到的
545481
Duplicate record
45
Duplicate record
11111
Your record count is ALWAYS going to be 1. You're have 您的记录数始终为1。
SELECT count(*) FROM companies WHERE MC = somevalue
This always returns a single row, aka a record count of 1. Perhaps it is the VALUE of the count that you are trying to get? 这总是返回单行,也就是记录计数1。也许是您要获取的计数值?
You can check a row exists or not by using this: 您可以使用以下方法检查行是否存在:
SELECT EXISTS(SELECT 1 FROM table1 WHERE ...)
It is more efficient than count(*).Hope it helps. 它比count(*)更有效,希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.