1. 添加数据:
1 //添加数据 2 3 $strsql = "insert into user_info(userId,userName,phoneNumber,userScore,dataTime) values(null,‘$name‘,‘$phone‘,‘$score‘,now())"; 4 $result = @mysql_query($strsql); 5 6 //成功添加 7 if($result) 8 { 9 echo true; 10 }else{ 11 echo false; 12 }
2. 删除数据:
3. 数据库查询示例代码:
1 //查询用户数据并返回用户数组对象 2 $strSql = "SELECT * FROM user_info"; //SQL查询语句 3 mysql_query("SET NAMES utf8"); 4 $result = mysql_query($strSql); //获取数据集 5 6 $users;$user;$i=0; 7 while($row=mysql_fetch_array($result)) 8 { 9 $user["userId"]=$row["userId"]; 10 $user["userName"]=$row["userName"]; 11 $user["phoneNumber"]=$row["phoneNumber"]; 12 $user["userScore"]=$row["userScore"]; 13 $user["dataTime"]=$row["dataTime"]; 14 $users[$i++]=$user; 15 } 16 //echo $strSql; 17 echo urldecode(json_encode($users));
//记数查询,返回数据条数 $strSql = "select count(*) from user_info"; //SQL查询语句 mysql_query("SET NAMES utf8"); $result = mysql_query($strSql); //获取数据集 $row=mysql_fetch_array($result); echo $row[0];
4. 修改数据:
//更新数据 $query="update question set question=‘$question‘,answer1=‘$answer1‘,answer2=‘$answer2‘,answer3=‘$answer3‘,answer4=‘$answer4‘,result=$result where id=$id"; $rs=mysql_query($query);//执行查询 if($rs){ echo true; }else{ echo false; }
时间: 2024-11-09 01:38:35