mysqli 代表 MySQL Improved,為 PHP 5 新增的擴充套件,支援 MySQL 4.1+ 新特性。主要目標:
mysql 模組$link = mysqli_connect('localhost', 'user', 'password', 'world');
if (!$link) die('Connect Error: ' . mysqli_connect_error());
if ($result = mysqli_query($link, 'SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {
while ($row = mysqli_fetch_assoc($result)) {
printf("%s (%s)\n", $row['Name'], $row['Population']);
}
mysqli_free_result($result);
}
mysqli_close($link);
$mysqli = new mysqli('localhost', 'user', 'password', 'world');
if (mysqli_connect_errno()) die('Connect Error: ' . mysqli_connect_error());
if ($result = $mysqli->query('SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {
while ($row = $result->fetch_assoc()) {
printf("%s (%s)\n", $row['Name'], $row['Population']);
}
$result->close();
}
$mysqli->close();
multi_query() 一次執行多條 SQLautocommit()、commit()、rollback()完整文件請參考 Zend 官方文章。