为什么我的 SQLSRV 查询没有执行?
在 IF ELSE 失败时,它没有像它应该的那样回应任何东西有人看到我的问题是什么吗?我不知道出了什么问题,看起来它应该对我有用。
PHP代码:
/* IF NULL EXISTS of DATEIN or DATEOUT then UPDATE else INSERT*/
$datein_s="SELECT TOP 1 datein FROM clocked WHERE datein IS NULL AND userid=? ORDER BY datein DESC";
$datein_sr=sqlsrv_query($dbconnect,$datein_s,$params);
$datein=sqlsrv_fetch($datein_sr);
$datein_q1="UPDATE clocked SET datein=GETDATE() WHERE EXISTS(SELECT TOP 1 datein FROM clocked WHERE datein IS NULL AND userid=? ORDER BY datein DESC);";
$datein_qr1=sqlsrv_query($dbconnect,$datein_q1,$params);
$datein_q2="INSERT INTO clocked(datein) VALUES(GETDATE(),?);";
$datein_qr2=sqlsrv_query($dbconnect,$datein_q2,$params);
$dateout_s="SELECT TOP 1 dateout FROM clocked WHERE dateout IS NULL AND userid=? ORDER BY dateout DESC";
$dateout_sr=sqlsrv_query($dbconnect,$dateout_s,$params);
$dateout=sqlsrv_fetch($dateout_sr);
$dateout_q1="UPDATE clocked SET dateout=GETDATE() WHERE EXISTS(SELECT TOP 1 dateout FROM clocked WHERE dateout IS NULL AND userid=? ORDER BY dateout DESC);";
$dateout_qr1=sqlsrv_query($dbconnect,$dateout_q1,$params);
if($datein===null)
{
$datein_qr1;
}
else if ($dateout===null)
{
$dateout_qr1;
}
else if ($datein===null&&$dateout===null)
{
$datein_qr1;
}
else if ($datein!==null&&$dateout!==null)
{
$datein_qr2;
}
else
{
echo "ERROR your query may be broken!";
}
/* END IF */