2013-04-10 109 views
1

因此,我使用的是usercake(开放源码的php mysql组合用于用户管理)。无论如何,我已经安装并完美地工作没有问题。由于我希望我的注册不包含显示名称和用户名,我已经在所有代码中删除了显示名称,这包括mysqldb和任何其他被称为或在香草安装中使用的位置。我的老用户仍然可以正常登录和正常工作,但是在注册新用户时出现错误我无法弄清楚(我对mysql/php相当陌生,所以我希望这里有人能帮我解释我的日志文件为这是我第一次没有需要引用它们) 先在这里是真正准备数据/插入MySQL的(全部逃逸,清洁离开了)sql语句已准备好但未执行(根据日志)

$stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."users (
      user_name, 
      password, 
      email, 
      activation_token, 
      last_activation_request, 
      lost_password_request, 
      active, 
      title, 
      sign_up_stamp, 
      last_sign_in_stamp 
     ) 
      VALUES (
      ?, 
      ?, 
      ?, 
      ?, 
      '".time()."', 
      '0', 
      ?, 
      'New Member', 
      '".time()."', 
      '0' 
     )"); 

$stmt->bind_param("sssssi", $this->username, $secure_pass, $this->clean_email, $this->activation_token, $this->user_active); 
     $stmt->execute(); 
     $inserted_id = $mysqli->insert_id; 
     $stmt->close(); 

//Insert default permission into matches table 
$stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."user_permission_matches (
     user_id, 
     permission_id 
     ) 
     VALUES (
     ?, 
     '1' 
     )"); 
$stmt->bind_param("s", $inserted_id); 
$stmt->execute(); 
$stmt->close(); 

所以一切之上,我认为(关键字代码)现在所有的好在这里日志mysql日志文件从上面的代码被称为

  65 Prepare INSERT INTO uc_users (
       user_name, 
       password, 
       email, 
       activation_token, 
       last_activation_request, 
       lost_password_request, 
       active, 
       title, 
       sign_up_stamp, 
       last_sign_in_stamp 
       ) 
       VALUES (
       ?, 
       ?, 
       ?, 
       ?, 
       '1365565745', 
       '0', 
       ?, 
       'New Member', 
       '1365565745', 
       '0' 
       ) 
     65 Close stmt  
     65 Prepare INSERT INTO uc_user_permission_matches (
       user_id, 
       permission_id 
       ) 
       VALUES (
       ?, 
       '1' 
       ) 
     65 Execute INSERT INTO uc_user_permission_matches (
       user_id, 
       permission_id 
       ) 
       VALUES (
       '0', 
       '1' 
       ) 

现在有两件事我不impan d所有发布在第一个以上的相关内容都是为什么Execute INSERT INTO uc_user (...从不叫?其次为什么其余的代码执行(并以某种方式将user_id插入到uc_user中)并将其正确传递到uc_user_permision_matches

part2对任何人更熟悉UserCake的内部工作什么是这个值绑定到sssssi因为我无法找到其他地方的引用?

+0

被包裹在一个事务中的查询? 'ssssiii'只是表示绑定过程中预期的占位符(通过数据类型)(s = string,i = int)。 – 2013-04-11 00:11:53

+0

不完全确定事务是什么 – brendosthoughts 2013-04-11 00:31:49

+0

没关系,查询没有被包装在一个事务中它们被简单地执行以便在这个时候没有数据库回滚(这解释了'uc_user_permission_matches'更新)。然而,为什么我的插入到uc_user没有得到执行? ...这是我目前的主要问题 – brendosthoughts 2013-04-11 00:47:34

回答

2

看起来问题是MySQL拒绝插入查询INSERT INTO uc_user_permission_matches,因为user_id是0,这导致我相信以前的查询没有正确完成。

它看起来像你的第一个查询你有5个占位符,但您正在尝试绑定6,试试这个:

// Remove one of the s placeholders 
$stmt->bind_param("ssssi", $this->username, $secure_pass, $this->clean_email, $this->activation_token, $this->user_active); 
+0

没问题,你肯定是对的,现在我需要所有这些变量的绑定所以,ive添加了一个额外的占位符,而不是'?'和表名应该这样做呢? – brendosthoughts 2013-04-11 01:12:01