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;
既然你已經指定['自動提交(FALSE)'](http://www.php.net/manual/en/mysqli.autocommit.php),其中你[手動提交](http://php.net/manual/en/mysqli.commit.php)你的交易? – eggyal