色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

mysql數據庫應用筆記

錢多多2年前13瀏覽0評論

MySQL是一種關系型數據庫管理系統,在許多網站和應用程序中被廣泛使用。在這篇文章中,我們將探討一些MySQL數據庫的應用筆記。

1. 連接數據庫

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// 創建連接
$conn = new mysqli($servername, $username, $password, $dbname);
// 檢測連接
if ($conn->connect_error) {
die("連接失敗: " . $conn->connect_error);
}
echo "連接成功";

2. 創建數據庫

$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "數據庫創建成功";
} else {
echo "Error creating database: " . $conn->error;
}

3. 創建數據表

$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
if ($conn->query($sql) === TRUE) {
echo "數據表 MyGuests 創建成功";
} else {
echo "創建數據表錯誤: " . $conn->error;
}

4. 插入數據

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "新記錄插入成功";
} else {
echo "Error: " . $sql . "
" . $conn->error; }

5. 查詢數據

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows >0) {
// 輸出每行數據
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "
"; } } else { echo "0 結果"; }

以上是一些MySQL數據庫的應用筆記,希望這篇文章能夠幫助到大家。