In order to try the network programming, read a lot of great God's blog, now this record to prevent forgetting.
We have to do a few things before we write the connection code:
1. Build Wamp
2. Create a database
3. Write the PHP code well
4. Testing
First, the installation of Wamp
This is relatively simple, I have to find a installation package from the Internet installed OK.
Second, create a database
I went to the Internet under a navicat for MySQL, you can visualize the database operation, convenient later operation. (1) Fill in the above IP, the user name, the password is good; (2) Create a new database in the connection user; (3) Create a new table in the new database, then click on the design table creating the data name and the data type you need, and finish the preparation of the database. Here's what to prepare for PHP.
Third, write a good php file: rank.php
My code is for my flappybrid to do the leaderboard, the code is as follows:
$score _max)//If the same name is compared with the previous data, if it is larger than the previous update data {$sql = "Update user set score= ' $score _ ' where name= ' $name _ '"; mysql_query ($sql );}} else{//Insert new data with the same name $sql= "INSERT into User (Name,score) VALUES (' $name _ ', ' $score _ ')"; mysql_query ($sql);} $li = "select* from user where 1 = 1 ORDER BY score Desc"; $result =mysql_query ($li, $link); for ($count =1; ($row =mysql_fetch_array ($result)) && ($count
<><11);$count++) { 选出前十并输出 ="" $li="$row['name']; " echo="" $row['name']."-="">"; echo $row [' score ']; if ($count
<11);$count++) {>
Iv. Enter the URL in the browser http://127.0.0.1/rank.php?name=bak&score=7758
The page shows bak->7758, and you can add a few more different data.
The above describes the Cocos2d-x curl+php network programming to do the leaderboard (a), including the cocos2d-x aspects of the content, I hope that the PHP tutorial interested in a friend helpful.