简体   繁体   English

MySQLi准备的语句:插入值的增量

[英]MySQLi prepared statements: insert increment of a value

Is it possible in any way to insert an increment of a certain column value ? 是否可以通过任何方式插入某个列值的增量?

$stmt->$this->mysqli->prepare('INSERT INTO `users` ( `email`,`date_added`,`playCount`) VALUES ( ?, NOW(), ? )');

$stmt -> bind_param('si',$email, WHAT); // playCount++ somehow ...
$stmt -> execute(); 

I know I can use UPDATE to do that, but then I need to check if user exists first and then do INSERT and afterward UPDATE just for one column? 我知道我可以使用UPDATE来做到这一点,但是然后我需要先检查用户是否存在,然后仅对一个列进行INSERT和之后的UPDATE操作? There should be a better approach I think? 我认为应该有更好的方法吗?

EDIT: UPDATE also won't work (won't prepare successfully-returns false: any ideas what might be wrong?) 编辑:更新也将不起作用(不会成功准备-返回false:任何想法可能出什么问题了?)

$stmt = $this->mysqli->prepare('UPDATE `users` SET `newsletter` = ?, `date_last` = NOW(),  points=points+?,  WHERE `email` = ?');

( reference ) 参考

"INSERT INTO users ( `email`,`date_added`,`playCount`) 
VALUES ( ?, NOW(), (SELECT MAX(playCount) from users)+1 );"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM