pdo insert有返回index,数据库却没有新增数据

调用以下函数插入后,lastinsertid返回数字每次都+1,但表就是空的。在数据库管理页面上直接添加一行,也发现id是增加了的。

function insert_del($operator='insert', $openid) {

global $pdo;
if ($operator='insert') {
    $sql = "insert openid (openid, voilate_times, timestamp) values (:openid, :voilate_times, :timestamp)";
    $sth = $pdo->prepare($sql);
    $sth->execute(['openid'=>$openid, 'voilate_times'=>1, 'timestamp'=>time()]);
    echo $pdo->lastInsertId();
}

if ($operator='del') {
    $sql = "delete from openid where openid=:openid";
    $sth = $pdo->prepare($sql);
    $sth->execute(['openid'=>$openid]);
}

$pdo = null;

}

阅读 2k
1 个回答

if里面写错了,你想写判断,但是写成了赋值,你每次运行都是先插入,又删除了,if里面改为双等号

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题