diff --git "a/\345\220\264\351\207\217/20220523--php\350\277\236\346\216\245mysql\345\242\236\345\210\240\346\224\271\346\237\245.md" "b/\345\220\264\351\207\217/20220523--php\350\277\236\346\216\245mysql\345\242\236\345\210\240\346\224\271\346\237\245.md" new file mode 100644 index 0000000000000000000000000000000000000000..fe473427f0c90484ba2e50a1e4af26c7091d4244 --- /dev/null +++ "b/\345\220\264\351\207\217/20220523--php\350\277\236\346\216\245mysql\345\242\236\345\210\240\346\224\271\346\237\245.md" @@ -0,0 +1,89 @@ +```php +'; + $initialize = "drop table user"; + $itl = mysqli_query($database,$initialize); + $ct = mysqli_query($database,$create); + if ($itl){ + echo '初始化成功
'; + + }else{ + echo '初始化失败,错误内容:'.mysqli_error($database).'
'; + } + +}else{ + echo '连接失败,错误内容:'.mysqli_connect_error().'
'; +} +$ins = "insert into user values (1,'陈小龙',98.5), + (2,'吴大虫',75.5), + (3,'陈得胜',66)"; +$ss = mysqli_query($database,$ins);//插入数据 +if ($ss){ + echo '数据插入成功
'; + $selects = "select * from user"; + $ss2= mysqli_query($database,$selects); + while($a=mysqli_fetch_assoc($ss2)){ + echo '编号:'.$a['id'].'
'.'名字:'.$a['name'].'
'.'分数:'.$a['score'].'

'; + } +}else{ + echo '数据插入失败,错误内容:'.mysqli_error($database).'
'; +} +echo "
"; +$add = "ALTER TABLE user ADD sex varchar(10)";//添加新的字段'sex' +$ss = mysqli_query($database,$add); +if ($ss){ + echo '成功添加新的字段
'; +}else{ + echo '添加失败'.mysqli_error($database).'
'; +} +$select = "select * from user where id=1"; +$ss = mysqli_query($database,$select); +if ($ss){ + echo '查询成功
'; + while($a=mysqli_fetch_assoc($ss)){ + echo '编号:'.$a['id'].'
'.'名字:'.$a['name'].'
'.'分数:'.$a['score'].'
'.'性别:'.$a['sex'].'
'; + } + +}else{ + echo '查询失败,失败原因:'.mysqli_error($database).'
'; +} +$delete = "delete from user where id=1";//三渠id为1的用户 +$ss = mysqli_query($database,$delete); +if ($ss){ + echo '三渠成功!
'; + $select = "select * from user"; + $ss2= mysqli_query($database,$select); + while($a=mysqli_fetch_assoc($ss2)) { + echo '编号:'.$a['id'].'
'.'名字:'.$a['name'].'
'.'分数:'.$a['score'].'
'.'性别:'.$a['sex'].'

'; + } + echo "
"; +}else{ + echo '三渠失败,失败原因:'.mysqli_error($database).'
'; +} +$update = "update user set sex='男' where name='吴大虫'";//修改吴大虫的性别为男 +$ss = mysqli_query($database,$update); +if ($ss){ + echo "修改成功
"; + $select = "select * from user"; + $ss2= mysqli_query($database,$select); + while($a=mysqli_fetch_assoc($ss2)) { + echo '编号:'.$a['id'].'
'.'名字:'.$a['name'].'
'.'分数:'.$a['score'].'
'.'性别:'.$a['sex']. '

'; + } +}else{ + echo '修改失败,失败原因:'.mysqli_error($database).'
'; +} +``` +