Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

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;

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...