From 84f878d339c078c8650540f1615af61d3bfe9387 Mon Sep 17 00:00:00 2001 From: xushiheng <2363492796@qq.com> Date: Mon, 23 May 2022 22:40:15 +0800 Subject: [PATCH] 3 --- ...hp\346\225\260\346\215\256\345\272\223.md" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "\345\276\220\350\257\227\346\201\222/20220523-php\346\225\260\346\215\256\345\272\223.md" diff --git "a/\345\276\220\350\257\227\346\201\222/20220523-php\346\225\260\346\215\256\345\272\223.md" "b/\345\276\220\350\257\227\346\201\222/20220523-php\346\225\260\346\215\256\345\272\223.md" new file mode 100644 index 0000000..bb9e040 --- /dev/null +++ "b/\345\276\220\350\257\227\346\201\222/20220523-php\346\225\260\346\215\256\345\272\223.md" @@ -0,0 +1,95 @@ +```sql +-- Mysql中新建个student数据库,里面有个学生信息表user +create database Student charset utf8; +use Student; +create table user( +id int primary key auto_increment, +name varchar(100) not null, +score decimal(4,1) not null +); +``` + + + +```php +// 完成PHP访问数据库五步。使用mysqli扩展对mysql数据库中的学生信息表进行增删改查。 + +"; +}else{ + echo "添加失败
"; +} +//删除数据 +$sql2= "delete from `user` where `id`=10"; +$res2= mysqli_query($con,$sql2); +if ($res2){ + echo "删除成功
"; +}else{ + echo "删除失败
"; +} +//修改数据 +$sql3= "update `user` set `name`='小明' where `id`=12 "; +$res3 = mysqli_query($con,$sql3); +if ($res3){ + echo "修改成功
"; +}else{ + echo "修改失败
"; +} +//查找数据 +$sql4 = "select * from `user`"; +$res4 = mysqli_query($con,$sql4) or die("查找失败
"); + + +while($a=mysqli_fetch_assoc($res4) ){ + echo $a['id']." ".$a['name']." ".$a['score']."
"; +} + + + + +``` + +连接数据库: + +```php +mysqli_connect(服务器地址,用户名,密码,数据库名,端口号,socket ); +``` + + + +查找错误: + +```php +mysql_error()://获取出错对应的提示信息 +``` + + + +查询: + +```php +mysqli_fetch_all*($result*);// 将整个结果集以二维数组返回 + +mysqli_fetch_array*($result*);// 将结果集里的一行返回成数组,有索引又有关联 + +mysql_fetch_assoc()://获取关联数组,表的表单名字作为数组下标,元素值作为数组元素值 + +mysqli_fetch_row *($result*);// 从结果集中取得一行作为索引数组 + +mysqli_fetch_object($result)); // 从结果集中取得一行作为对象 + +mysqli_affected_rows($connect);// 返回最近一次query操作受影响的行数 +``` + + + -- Gitee