PHP PDO simple insert or update function

后端 未结 4 1658
不思量自难忘°
不思量自难忘° 2021-01-18 01:23

In trying to create a simple PHP PDO update function that if the field is not found would insert it, I created this little snippet.

function updateorcreate($         


        
4条回答
  •  甜味超标
    2021-01-18 02:08

    You will first need to execute it.

    Apart from that, this is a dodgy way of doing this. It would be better to start a transaction, do a SELECT and then determine what to do (INSERT or UPDATE). Just checking whether the UPDATE query succeeded doesn't suffice, it succeeds when no row is found too.

提交回复
热议问题