In order to try network programming, I read a lot of blogs by great people, so I will record this now so as not to forget it.
Before writing the connection code, we must do a few things first:
1. Build WAMP
2. Create a database
3. Write the PHP code
4. Test
1. Installation of wamp
This is relatively simple. I found an installation package from the Internet and installed it.
2. Create a database
I went online and downloaded Navicat for MySQL, which can visually operate the database and facilitate future operations. (1) Just fill in the IP, user name, and password above; (2) Create a new database user in the connection; (3) Create a new table in the newly created database, and then click Design Table to create what you need Data name and its data type; after completing the above steps of database preparation, the following is the preparation of PHP.
3. Write the PHP file: rank.php
This code is for my flappybrid to make rankings. The code is as follows:
<?php header("content-Type: text/html; charset=utf-8"); $link =@mysql_connect("localhost","root",""); if(!$link) { die('Could not connect: ' . mysql_error()); } mysql_query("set names utf8",$link); mysql_select_db("user",$link); //连接数据库 $name_=$_GET["name"];//用GET的方法获取数据 $score_=$_GET["score"]; $sql="select* from user where name='$name_'"; $result=mysql_query($sql);//查找有没有同名的 $row=mysql_fetch_array($result); if($row) { $score_max =$row['score']; if($score_>$score_max) //如果有同名就跟之前的数据比较,如果比之前大就更新数据 { $sql="update user set score='$score_' where name='$name_'"; mysql_query($sql); } } else {//同名就插入新数据 $sql="insert into user(name,score) values('$name_','$score_')"; mysql_query($sql); <span style="white-space:pre"> </span>} $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<mysql_num_rows($result)+1)&&($count<11);$count++)  {//选出前十并输出   $li= $row['name'];   echo $row['name']."->"; echo $row['score']; if($count<mysql_num_rows($result))  {echo ",";}     } ?>
The page displays bak->7758, and you can add different data several times.
The above introduces the cocos2d-x curl+PHP network programming ranking list (1), including the content of Cocos2d-X. I hope it will be helpful to friends who are interested in PHP tutorials.