MySQLi不工作,没有错误,没有插入的信息


MySQLi is not working , no errors , no inserted info

我一直在做所有人告诉我让它工作,但没有错误,也没有插入行:

知道吗?

private $db;
// Constructor - open DB connection
function __construct() 
{
    $this->db = new mysqli('localhost', 'root', '', 'sampleinyoudb');
    $this->db->autocommit(FALSE);
    if (mysqli_connect_errno()) 
    {
        sendResponse(500, "Could not connect to the database!");
        exit();
    }
}
// Destructor - close DB connection
function __destruct() 
{
    $this->db->close();
}

        if($stmt = $this->db->prepare("INSERT INTO Users (id,email) VALUES (?, ?)"))
        {
            $test1 = 1; //Empty
            $test2 = 'asdasd@gmail.com'; //Empty
            $stmt->bind_param("is", $test1, $test2);
            $stmt->execute();   
            if ( false===$stmt ) 
            {
              die('execute() failed: ' . htmlspecialchars($mysqli->error));
            }               
            $stmt -> close();
        }
        else
        {
            printf("Prepared Statement Error: %s'n", $this->db->error);
        }
        echo 'Any Errors: '.$this->db->error.PHP_EOL;

您已经指定了autocommit(FALSE),但不是手动提交事务。 在$stmt->execute()后的某个时候,您必须输入:

$this->db->commit();