首先来说下 from和form.
这2个单词很容易写错,搞的我很郁闷:
from读音很长 翻译为来自..从哪.. from在歌曲里经常能听到. ||||||||||||||||||||||||||||||||||||||||||||||||| form的读音很短,翻译为表格.歌曲里几乎没有 记录下加深记忆.
增加语句 insert into:
//增加语句 $sql = "insert into user (name,email,age,sex) values ('黄蓉','hr@qq.com',26,0)"; if(mysqli_query($link,$sql)) { echo '添加成功! id为:'.mysqli_insert_id($link); }
删除语句 delete from:
//删除语句 $sql = "delete from user where id=4"; if(mysqli_query($link,$sql)) { echo '删除成功!'; }
修改语句 update 表 set
//修改语句 $sql = "update user set name = '洪七公',email='hqg@qq.com' where id=5"; if(mysqli_query($link,$sql)) { echo '修改成功!'; }
查询语句 select * from
//查数据 $sql = "select sex,name,email from user";//查询语句 注意from不要写错 $result = mysqli_query($link,$sql); //query()链接上数据库执行语句 if(mysqli_num_rows($result)>0){//是否查询的结果>0 while ($row = mysqli_fetch_assoc($result))//循环输出 { echo "姓名:" .$row['name'] .","; echo "邮箱:" .$row['email'] .","; echo "姓名:" .($row['sex'] == '0' ? '女' : '男')."<hr>"; }; }else{ echo '错误'; }