一,查询
<?php $conn= mysql_connect("127.0.0.1","lanou12","lanou12"); $fieldName=$_GET["name"]; if($conn) { mysql_select_db("Class_12_Lesson"); $sql="select ".$fieldName." from team_five;"; $result= mysql_query($sql);
$json=array(); $j=0; while($row=mysql_fetch_array($result)) { //dic $item=array(); for($i=0;$i< mysql_num_fields($result);$i++) { $key=mysql_field_name($result, $i); $value=$row[$key]; $item[$key]=$value; } //item put in json $json[$j]=$item; $j++; } echo(json_encode($json)); } else { echo("connect error!"); }
mysql_close($conn); ?>
二,插入
<?php $conn= mysql_connect("127.0.0.1","lanou12","lanou12"); if($conn) {
mysql_select_db("Class_12_Lesson"); $sql="insert into team_five(student_name,student_age) values('lichanghong',25)";
$result= mysql_query($sql); if($result) { echo("successfully..."); } else { echo("insert failed".$result); } } else { echo("connect error!"); } mysql_close($conn); ?>
|
请发表评论