2012-07-03 95 views
2

我一直在做所有的人都告诉我,使它的工作原理,但没有错误,没有插入的行:库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 = '[email protected]'; //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; 
+3

既然你已经指定['自动提交(FALSE)'](http://www.php.net/manual/en/mysqli.autocommit.php),其中你[手动提交](http://php.net/manual/en/mysqli.commit.php)你的交易? – eggyal

回答

相关问题