用了不到一天的时间搭好了PHP环境,并且写了一个连接数据进行查询并输出JSON的例子。没接触PHP之前,觉得很难 没想到静下心来以后看了1,2个小时就能写接口了。特此Mark JUST COOL!
<?php $con = mysql_connect("http://www.xxx.com","root","***"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM user order by createtime desc limit 20"); $arr=Array(); $index=0; while($row = mysql_fetch_array($result)) { $obj=new stdClass(); $obj->dt = $row['rid']; $obj->sexy = $row['sex']; $obj->address =$row['adress']; $arr[]=$obj; } echo json_encode($arr); //echo $row['createtime'] . " " . $row['sex']. " " . $row['adress']; echo "<br />"; mysql_close($con); ?>