dongqiulei6805 2014-10-21 19:12
浏览 64
已采纳

mysql更新php后的空值

i made a lot of research around here and Google but i cannot find an answer to this problem.

I update a field in a MySQL database with following code:

public function registerPubKey() {

    $stmt = $this->cn->prepare('UPDATE sb_user SET pubkey= ? WHERE email= ?');
    $exres = $stmt->execute(array($this->info["pubkey"],$this->info["email"]));
    if ($exres == false) { $resultArray["result"] = "Error registering public key"; echo json_encode($resultArray); exit; }

    $resultArray["result"] = "success"; echo json_encode($resultArray);
}

I'm sure that all works except that the field in the database is empty. I dumped the private variable $info and it contains the pubkey (pubkey is a base64 string).

I noticed that if I change the update query with an INSERT, the value is inserted correctly!

  • 写回答

1条回答 默认 最新

  • dongyun8891 2014-10-21 19:22
    关注

    It's likely because you're trying to UPDATE non existent rows. Try adding a ON DUPLICATE KEY before. See INSERT ... ON DUPLICATE KEY UPDATE Syntax. UPDATE returns nothing if the row does not exist.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义