gpt4 book ai didi

php - 如何避免 SQL 查询检查 IS NULL 的误报?

转载 作者:行者123 更新时间:2023-12-04 18:21:52 24 4
gpt4 key购买 nike

如何避免 SQL 查询检查 IS NULL 的误报?

我似乎通过添加 if(sqlsrv_has_rows 纠正了我的误报。陈述。

PHP:

/*

IF select of 1900 datein has rows
update datein

IF select of 1900 dateout has rows
update dateout

IF select of 1900 datein AND dateout no rows
insert datein

*/
$datein_s="SELECT TOP 1 datein FROM clocked WHERE datein='1900-01-01 00:00:00' AND userid=? ORDER BY datein DESC";
$datein_sr=sqlsrv_query($dbconnect,$datein_s,$params) or die("Error datein:".print_r(sqlsrv_errors(),true));
$datein=sqlsrv_fetch($datein_sr);
if(sqlsrv_has_rows($datein_sr)===FALSE)
{
$datein="NOROWS";
}
else
{
$datein="HASROWS";
}

$dateout_s="SELECT TOP 1 dateout FROM clocked WHERE dateout='1900-01-01 00:00:00' AND userid=? ORDER BY dateout DESC";
$dateout_sr=sqlsrv_query($dbconnect,$dateout_s,$params) or die("Error dateout:".print_r(sqlsrv_errors(),true));
$dateout=sqlsrv_fetch($dateout_sr);
echo $dateout;
if(sqlsrv_has_rows($dateout_sr)===FALSE)
{
$dateout="NOROWS";
}
else
{
$dateout="HASROWS";
}

if($datein==="HASROWS")
{
$datein_q1="UPDATE clocked SET datein=GETDATE() WHERE EXISTS(SELECT TOP 1 datein FROM clocked WHERE datein='1900-01-01 00:00:00' AND userid=? ORDER BY datein DESC);";
$datein_qr1=sqlsrv_query($dbconnect,$datein_q1,$params) or die("Error update datein:".print_r(sqlsrv_errors(),true));
echo "Datein and out are HASROWS";
}
else if ($dateout==="HASROWS")
{
$dateout_q1="UPDATE clocked SET dateout=GETDATE() WHERE EXISTS(SELECT TOP 1 dateout FROM clocked WHERE dateout='1900-01-01 00:00:00' AND userid=? ORDER BY dateout DESC);";
$dateout_qr1=sqlsrv_query($dbconnect,$dateout_q1,$params) or die("Error update dateout:".print_r(sqlsrv_errors(),true));
echo "Dateout NOROWS";
}
else if ($datein==="NOROWS"&&$dateout==="NOROWS")
{
$datein_q2="INSERT INTO clocked(datein,userid) VALUES(GETDATE(),?);";
$datein_qr2=sqlsrv_query($dbconnect,$datein_q2,$params) or die("Error insert datein:".print_r(sqlsrv_errors(),true));
echo "Datein and Dateout NOROWS";
}
else
{
echo "ERROR your query may be broken!";
}

最佳答案

我似乎通过添加 if(sqlsrv_has_rows 语句来纠正我的误报。

关于php - 如何避免 SQL 查询检查 IS NULL 的误报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10483557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com