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 idea自动补全键位冲突
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 定制ai直播实时换脸软件
  • ¥100 栈回溯相关,模块加载后KiExceptionDispatch无法正常回溯了
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页