PHP mysqli插入无法正常工作,但未给出任何错误 [英] PHP mysqli Insert not working, but not giving any errors

查看:63
本文介绍了PHP mysqli插入无法正常工作,但未给出任何错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我试图做一个简单的插入,但是实际上什么都没有插入到表中.我尝试打印出错误,但没有任何报告.

As the title says Im trying to do a simple insert, but nothing actually is inserted into the table. I try to print out errors, but nothing is reported.

我的用户"表中的字段比这4个字段多得多,但它们都应该是默认字段.

My users table has many more fields than these 4, but they should all default.

$query = 'INSERT INTO users (username, password, level, name) VALUES (?, ?, ?, ?)';
if($stmt = $db -> prepare($query))
{
    $stmt -> bind_param('ssis', $username, $password, $newlevel, $realname);
    $stmt -> execute();
    $stmt -> close();
    echo 'Any Errors: '.$db->error.PHP_EOL;
}

没有给出错误,但是当我去查看phpmyadmin中的表时,没有添加新行.我肯定知道类型正确(字符串和整数).这里真的有什么问题吗,还是与我忽略其他专栏的事实有关?我的用户表中大约有8列.

There are no errors given, but when I go to look at the table in phpmyadmin there is not a new row added. I know for sure that the types are correct (strings and integers). Is there something really wrong here or does it have something to do with the fact that I'm ignoring other columns. I have about 8 columns in the user table.

推荐答案

如果您关闭了自动提交功能,则在执行查询后必须显式调用commit方法.

If you have turned auto commit off, you will have to explicitly call the commit method after you execute the query.

$stmt->execute();
$db->commit();
$stmt->close();

这篇关于PHP mysqli插入无法正常工作,但未给出任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆