SQL Write operation set contents (array to string) Sqlset content SQL operations array to string
SQL Write operation set contents (array to string) [encapsulation Method]
- function getsqlset ( $data ) {
- $Str = ;
- foreach ( $data as $k = $v ) {
-
- $Str. = $k. "= '". $v. "',";
-
- }
- $Str = substr ($Str,0,-1);
- return $Str;
- }
If you are performing an insert operation (add a record to user)
- $data = array(
- ' name '=' Zhang San ',
- ' sex '=' man',
- ' Idcard '='341215645646545',
- ' address' = ' Huaguoshan ',
- );
- $str = Getsqlset ($data);
- $sql = "INSERT into user set {$STR}";//Insert ... Set method is extension method, single record insert operation ... values ... Fast Speed
- mysql_query ($sql);
2.SQL Insert ... values ... Array composition string method
- $data = array(
- ' name '=' Zhang San ',
- ' sex '=' man',
- ' Idcard ' = '
- ' address' = ' Huaguoshan ',
- );
- $insertkeys = Join ("' , ' ", Array_keys ($data));
- $insertvalues =" ' " . Join (" ", ' ", Array_values ($data)). " ";
- mysql_query ("INSERT into user ({$insertkeys}) VALUES ({$insertvalues})";
-Day Walk Jian, gentleman to self-improvement!
SQL Write operation set contents (array to String)