1. Add Data:
1 //Add Data2 3 $strsql= "INSERT into User_info (userid,username,phonenumber,userscore,datatime) VALUES (null, '$name‘,‘$phone‘,‘$score', Now ()) ";4 $result= @mysql_query($strsql);5 6 //successfully added7 if($result)8 {9 Echo true;Ten}Else{ One Echo false; A}
2. Delete data:
3. Database Query Sample code:
1 //querying user data and returning user array objects2 $STRSQL= "SELECT * from User_info";//SQL query Statements3 mysql_query("SET NAMES UTF8");4 $result=mysql_query($STRSQL);//Get Data Set5 6 $users;$user;$i=0;7 while($row=Mysql_fetch_array($result))8 {9 $user["UserId"]=$row["UserId"];Ten $user["UserName"]=$row["UserName"]; One $user["PhoneNumber"]=$row["PhoneNumber"]; A $user["Userscore"]=$row["Userscore"]; - $user["Datatime"]=$row["Datatime"]; - $users[$i++]=$user; the } - //echo $strSql; - Echo UrlDecode(Json_encode ($users));
// Count query, returns the number of data bars $STRSQL // SQL query Statements mysql_query ("SET NAMES UTF8"); $result mysql_query ($strSql// get data set $row=mysql_fetch_array($result); Echo $row [0];
4. Modify the data:
//Update Data$query= "Update question set question="$question', answer1= '$answer 1', answer2= '$answer 2', answer3= '$answer 3', answer4= '$answer 4', result=$resultwhere id=$id";$rs=mysql_query($query);//Execute Queryif($rs){ Echo true;}Else{ Echo false;}
Additions and deletions of phpstudy7--mysql database