dongweihuai5601 2015-12-08 15:57
浏览 5

PHP数据库类不提交

I'm creating a php class what is able to handle my query's and db connections.

I've played around with it for a while and did some research, now I've created m When I use the class for something to handle it does not commit, but I'm not able to see why it doesn't I don't get any error's and my mysqli error handling is correct.

does anyone have a idea what's wrong with my script?

sql class:

class sql{

    function convertArrayReferences($arr){
        $refs = array();
        foreach($arr as $key => $value)
            $refs[$key] = &$arr[$key];
        return $refs;
    }
    function database($database, $query, $parameters){
        $result;
        $mysqli = new mysqli("****", "****", "****", $database);

        if(mysqli_connect_errno()){
            return "Connect failed: %s
 " . mysqli_connect_error();
        }

        if(!$stmt = $mysqli->prepare($query)){
            return $mysqli->error;
        }

        if(!$stmt->bind_param($this->convertArrayReferences($parameters))){
            return $mysqli->error;
        }

        if(!$stmt->bind_result($result)){
            return $mysqli->error;
        }

        if(!$stmt->execute()){
            return $mysqli->error;
        }

        $stmt->close();

        return $mysqli->error;
    }  
}

the bit of code where the function is called:

$execute = $sql->database("survivalTmpReg",
"INSERT INTO USERS (name, surname, email, username, password) VALUES (?, ?, ?, ?, ?)",
array("sssss", $name, $surname, $email, $username, $password));

if($execute){
    $message = REGISTER_MESSAGE;
}else{
    $message = $execute;
}
  • 写回答

1条回答 默认 最新

  • dsj2222222 2015-12-08 16:08
    关注

    Statements are not automatically committed unless autocommit is turned on. On the first statement a transaction is created. Unless the transaction is not explicitly committed its changes will not be visible and eventually the transaction will be aborted by the system. MySQLi supports committing transactions using mysqli::commit.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c