MySQL是一種常用的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)。它支持增加、刪除、修改等基本操作。本文將介紹MySQL如何進行增加和刪除的操作。
// 連接數(shù)據(jù)庫 $conn = mysqli_connect("localhost", "root", "", "test"); // 檢查是否連接成功 if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } // 設(shè)置編碼格式 mysqli_set_charset($conn,"utf8");
增加新數(shù)據(jù):
// 插入數(shù)據(jù)到表中 $sql = "INSERT INTO students (name, age) VALUES ('John',20)"; if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "
" . mysqli_error($conn); }
刪除數(shù)據(jù):
// 刪除一條數(shù)據(jù) $sql = "DELETE FROM students WHERE name='John'"; if (mysqli_query($conn, $sql)) { echo "Record deleted successfully"; } else { echo "Error deleting record: " . mysqli_error($conn); }
以上是MySQL的增加和刪除操作,這些操作是數(shù)據(jù)庫管理中非常基礎(chǔ)和常見的操作。