欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

mysql5.5數(shù)據(jù)庫操作

阮建安2年前10瀏覽0評論

MySQL5.5是一種常用的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),可以對數(shù)據(jù)進(jìn)行存儲、管理、查詢等操作。以下是MySQL5.5數(shù)據(jù)庫操作的一些示例。

連接數(shù)據(jù)庫:

//連接MySQL服務(wù)器
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('連接失敗: ' . mysql_error());
}
//選擇數(shù)據(jù)庫
$db_selected = mysql_select_db('database', $link);
if (!$db_selected) {
die ('數(shù)據(jù)庫選擇失敗: ' . mysql_error());
}

創(chuàng)建數(shù)據(jù)表:

//創(chuàng)建表
$sql = "CREATE TABLE user (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
name VARCHAR(30) NOT NULL,
age INT(3) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
//執(zhí)行SQL語句
if (mysql_query($sql)) {
echo "數(shù)據(jù)表創(chuàng)建成功";
} else {
echo "創(chuàng)建數(shù)據(jù)表錯誤: " . mysql_error();
}

插入數(shù)據(jù):

//插入數(shù)據(jù)
$sql = "INSERT INTO user (name, age, email)
VALUES ('張三', 18, 'zhangsan@example.com')";
//執(zhí)行SQL語句
if (mysql_query($sql)) {
echo "數(shù)據(jù)插入成功";
} else {
echo "插入數(shù)據(jù)錯誤: " . mysql_error();
}

查詢數(shù)據(jù):

//查詢數(shù)據(jù)
$sql = "SELECT * FROM user";
$result = mysql_query($sql);
//輸出數(shù)據(jù)
if (mysql_num_rows($result) >0) {
while($row = mysql_fetch_assoc($result)) {
echo "姓名: " . $row["name"]. " 年齡: " . $row["age"]. " 郵箱: " . $row["email"]. "
"; } } else { echo "0 結(jié)果"; }

更新數(shù)據(jù):

//更新數(shù)據(jù)
$sql = "UPDATE user SET age=20 WHERE name='張三'";
//執(zhí)行SQL語句
if (mysql_query($sql)) {
echo "數(shù)據(jù)更新成功";
} else {
echo "更新數(shù)據(jù)錯誤: " . mysql_error();
}

刪除數(shù)據(jù):

//刪除數(shù)據(jù)
$sql = "DELETE FROM user WHERE name='張三'";
//執(zhí)行SQL語句
if (mysql_query($sql)) {
echo "數(shù)據(jù)刪除成功";
} else {
echo "刪除數(shù)據(jù)錯誤: " . mysql_error();
}
上一篇coolqdocker
下一篇ie不css3