Three ways to read data
Read database mode development Home interface
Get data from database--"package--" Generate interface number
Advantages: The system with high data timeliness
2. Read cache mode Development Home interface (very wide application)
Get information from database--"package--" return data
Request again--"cache--" return data
Pros: Reduce database pressure
3. Timed Read cache mode development interface
Database--"crontab (timed Generation)
Request--"cache--" return data
Development app can install tools: Start bluestacks Android Simulator
Read the database way out of the code implementation of the interface:
<?php/************************************* read the database How to develop the homepage interface * Learn php small ant * Blog http://my.oschina.net/ woshixiaomayi/blog*************************************///loading the DB class//code content written the day before yesterday please refer to http://my.oschina.net/ Woshixiaomayi/blog/518295require_once ('./db.php ');//Load the previously written interface response class//code contents please refer to http://my.oschina.net/ Woshixiaomayi/blog/517384require_once ('./response.php ');//Receive paging Data page for current page pagesize How much data $page=isset ($_get[' page ')? $_get[' page ']:1; $pagesize =isset ($_get[' pagesize '])? $_get[' pagesize ']:5 ;//Detect if these two values are numeric if (!is_numeric ($page) or !is_numeric ($pagesize)) {//Are not numbers, send error message/* The reason for the use of a return is to enhance the readability of the program, because programmers unfamiliar with the program, do not know that there is exit in the Show method, plus a return, the other people will know that after the execution of this step, the program will stop, the subsequent program will not be executed. Convenient for other people, everyone good is really good \ (^o^)/yes!*/return response::show (400, ' argument not valid ');} Set the offset required for paging $offset= ($page-1) * $pagesize;//write SQL statement $sql= "select * from actor limit ". $ Offset. ",". $pagesize;//If there is an error connecting to the database, obtain the information and return the customized information//To avoid exposing the error directly to the user try{$connect =db::getinstance ()->conNect ();} catch (exception $ea) {//error message returned to App Return response::show (' Mysql not connect ');} The database connection succeeds, executes the SQL statement, gets the result set $result=mysql_query ($sql, $connect); $index _data=array (); while ($row =mysql_fetch_assoc ($ Result) {$index _data[]= $row;} if ($index _data) {//required result data to get, return data return response::show (200, ' content obtained successfully ', $index _data);} else{//not get, return error prompt Return response::show (400, ' Home data acquisition failed '); >
Note Two points to note:
Add a return to make it easier for other people to read the code.
When the database is not connected successfully, an exception is obtained and a prompt message is returned.
Small Ant Learning App Interface Development (6)--app Interface Instance--the case realization of the home data interface