2

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

任何的想法?

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;
4

1 回答 1

6

您已指定autocommit(FALSE),但未手动提交您的事务。在某些时候,$stmt->execute()您必须放置:

$this->db->commit();
于 2012-07-03T11:12:04.877 回答