MySQL是一種常見的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),常被用于開發(fā)網(wǎng)頁。它提供了可靠的數(shù)據(jù)存儲和訪問,是大多數(shù)網(wǎng)站的核心組成部分。下面將介紹一些用MySQL開發(fā)網(wǎng)頁時常用的操作。
1. 連接到數(shù)據(jù)庫
connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?>
2. 執(zhí)行SQL查詢語句
query($sql); if ($result->num_rows >0) { while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["name"]. " - Age: " . $row["age"]. "
"; } } else { echo "0 results"; } $conn->close(); ?>
3. 插入數(shù)據(jù)
query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "
" . $conn->error; } $conn->close(); ?>
4. 更新數(shù)據(jù)
query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; } $conn->close(); ?>
5. 刪除數(shù)據(jù)
query($sql) === TRUE) { echo "Record deleted successfully"; } else { echo "Error deleting record: " . $conn->error; } $conn->close(); ?>
通過MySQL,我們可以輕松地進行各種網(wǎng)絡(luò)應(yīng)用程序的開發(fā)。采用像以上所示的方法,可以實現(xiàn)對數(shù)據(jù)庫的訪問和數(shù)據(jù)的操作。