微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP:在准备好的语句上获取插入确认

我是准备陈述的新手,并试图让一些简单的工作.

这是我的数据库表:

`unblocker_users` (
  `uno` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_email` varchar(210) DEFAULT NULL,
  `pw_hash` varchar(30) DEFAULT NULL,
  `email_confirmed` tinyint(4) DEFAULT NULL,
  `total_requests` bigint(20) DEFAULT NULL,
  `today_date` date DEFAULT NULL,
  `accessed_today` tinyint(4) DEFAULT NULL,)

这是我插入一些测试数据的功能

function add_new_user($e_mail1)
    {
    require_once "db.PHP";

$stmt = $MysqLi->prepare("INSERT INTO unblocker_users VALUES ('',?, ?,0,0,?,0)");
$stmt->bind_param('sss', $e_mail1, $this->genRandomString(1),$this->today_date()); 

$stmt->execute();

$stmt->close(); 
// ####### Below line is giving an error ########
$done = $stmt->affected_rows;

return $done;
    }

正如您在上面所看到的,我已经标记了给我一个错误的行.

Warning: unblocker_class::add_new_user() [unblocker-class.add-new-user]: Property access is not allowed yet in...

我哪里做错了?
我怎样才能得到某种成功插入行的确认?

谢谢!

解决方法:

在要访问受影响的行之前关闭准备好的语句

$done = $stmt->affected_rows;
$stmt->close(); 

return $done;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐