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

时间:2012-07-03 11:08:04

标签: php mysqli

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

有什么想法吗?

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;

1 个答案:

答案 0 :(得分:6)

您已指定autocommit(FALSE),但不是manually committing您的交易。在$stmt->execute()之后的某个时刻,你必须把:

$this->db->commit();