1. Database Connection configmysql.php
<? PHP $q mysql_connect ("localhost:8889", "root", "root"); if (! $q ) { diemysql_error()); } mysql_query // read Data//mysql_select_db with UTF8 ("MyDB", $q);//Select Database ?>
2.POST or GET request, JSON returns selectuser.php
<?include("configmysql.php"); mysql_select_db("MyDB",$q);//Select the database//get or post parameters or $TEMPid=$_get[' UserID ']; //$TEMPid =$_post[' userid ']; $sql= "SELECT * from USERINFOTB where userid=".$TEMPid; $query=mysql_query($sql) or die(Mysql_error()); while($row=Mysql_fetch_array($query)){ $json=$row; } EchoJson_encode ($json);?>
3. Multiple sets of data selectuser.php
<?include("configmysql.php"); mysql_select_db("Chepaidb",$q);//Database $TEMPid=$_get[' DriverID ']; $sql= "SELECT * from Driverinfo where driverid=".$TEMPid; $query=mysql_query($sql) or die(Mysql_error()); while($row=Mysql_fetch_array($query)){ $json 1=$row; } $sql 2= "SELECT * from Driverillegalinfo where idriverid=".$TEMPid. "ORDER BY Iid Desc"; $query 2=mysql_query($sql 2) or die(Mysql_error()); $json 2=Array(); $sum=0; while($row 2=Mysql_fetch_array($query 2)){ $json 2[' Row '.$sum] =$row 2; $sum++; } $newJson=Json_encode (Array_merge( Array(' info1 ' =$json 1),Array(' Info2 ' =$json 2) ) ); Echo $newJson;?>
4. File photo Upload upload_file.php
<?Header("content-type:text/html; Charset=utf-8 "); include("configmysql.php"); mysql_select_db("Chepaidb",$q);//database//post Get key-value pair parameters $TEMPid=$_post[' DriverID ']; Echo"\ndriverid is".$TEMPid." \ n "; foreach($_files as $_eachfile) { //file Processing if($_eachfile["error"] > 0) { Echo"Error:".$_eachfile["Error"]. "\ n"; } Else { Echo"File name:".$_eachfile["Name"]. "\ n"; Echo"Type:".$_eachfile["Type"]. "\ n"; Echo"Size:". ($_eachfile["Size"]/1024). "Kb\n"; } if(file_exists("uploadimage/".$_eachfile["Name"])) { Echo $_eachfile["Name"]. "The file already exists."; } Else { Move_uploaded_file($_eachfile["Tmp_name"], "uploadimage/".$_eachfile["Name"]); Echo"The file has been stored in:". " uploadimage/".$_eachfile["Name"]. " \ n "; } } /*//file file processing if ($_files["file" ["error"] > 0) {echo "Error:". $_files["File" ["Error"]. "\ n"; } else {echo "file name:". $_files["File" ["Name"]. "\ n"; echo "Type:". $_files["File" ["type"]. "\ n"; echo "Size:". ($_files["File" ["Size"]/1024). "Kb\n"; } if (File_exists ("uploadimage/". $_files["File" ["Name"])) {echo $_files["file" ["Name"]. "The file already exists."; } else {move_uploaded_file ($_files["file"] ["Tmp_name"], "uploadimage/". $_files["File" ["Nam E "]); echo "file has been stored in:". " uploadimage/". $_files["File" ["Name"]. " \ n "; } */?>
[PHP as the iOS backend JSON format HTTP communication and file upload implementation]