如果行等于true更新,如果不插入PHP

时间:2018-04-13 14:11:46

标签: php sql-server

编辑:你好!

环境:使用PHP 7.1.15和DB SQL服务器运行。

如果字段存在,我想更新,否则插入新行。

我使用“sql_has_rows”来检查一条线是否已经存在。 执行查询时,浏览器不会显示错误,但不会修改表

编辑:2

$stmt = "SELECT * FROM dbo.MyTable where Client = '$Client' and Contact = '$Contact' and Jira = '$Jira'";
$params1 = array($Client, $Jira, $Contact, $lvlsatisfaction, $Commentaire);                       
$result = sqlsrv_query($conn, $stmt, $params1);

if ($result) {
   $rows = sqlsrv_has_rows( $result ); 
   if ($rows === false){
    "INSERT INTO dbo.MyTable (Client, Jira, Contact, lvlsatisfaction, Commentaire, DateEnregistrement, HeureEnregistrement)
    values (?,?,?,?,?, convert (date, getdate()), convert (time, getdate()))";
   }else{
    "UPDATE dbo.MyTable set lvlsatisfaction = (?), Commentaire = (?), DateEnregistrement = (convert (date, getdate())), HeureEnregistrement = (convert (time, getdate()))
    where Client = '$Client' and Contact = '$Contact' and Jira = '$Jira'" ;
}

}

0 个答案:

没有答案