Well, the environment is also set up the tools also have that we began to write PHP program, the last section we said the site of our local directory for d:/phpwww, you create a new testphp directory inside, the name casually up, it indicates this time your job storage location, but must be in English. Yes, there is no database, the first step of course is to establish their own server database.
1. Database setup
In Phpstudy MySQL Manager we click Mysql-front, open the MySQL front end tool, a "Open login information ..." dialog box, directly click the Open button to enter
After entering the interface is still very clear, the left is the tree structure to show which database you have, on the "localhost" root node right-click on the new database "game", it looks like this:
In the Game database node right-click New-"table, create a new data table Newsuser table, to hold the user name and password, table structure such as: that ID is the system self-built equivalent to the primary key.
Click Data Browser, you can enter the table data, for example, after entering a line right click on a grid can insert a new record and delete the bank record.
Other detailed usage of this tool I do not want to say more, is completely stupid, even my IQ is so mediocre people can read that for the reader is difficult to live.
2. PHP Server Program
We write two modules, one is the registration of one is to verify the login, first look at the registration program how to write
Registered:
In the site root directory (d:/phpwww) testphp directory, we first create a new reguser.php file, with the tool we mentioned in the previous section Phpdesigner writing, the code is as follows:
<?php/** * @author blog.anchen8.net * @copyright * */$US = $_get["uname"]; Get the uname field from the parameter, i.e. user name $ps = $_get["UPass"]; From the parameters to get the UPass field, that is, password//To establish a MySQL database connection, address is 127.0.0.1, login is root, password is root$conn = mysql_connect ("127.0.0.1", "root", "root") ;//Open Database mysql_select_db ("game");//new insert Query $sql = "INSERT into Newsuser (uname, UPass) VALUES ('". $US. "', '". $ps. "')"; /execute this query mysql_query ($sql);//Close Database Mysql_close ($conn); echo "1, Insertok";? >
The notes are clear, copy on the line.
The above implementation of the user registration logic, want to see the effect can be entered in the browser http://127.0.0.1/testPhp/reguser.php?uname=wang&upass=123 to add a user, the page display "1,insertok "Indicates that the add user successfully opened the MySQL database to check for added success.
Verify Login:
Create a new checklogin02.php file in the testphp directory with the following code:
<?php/** * @author blog.anchen8.net * @copyright * */$US =$_get["uname"]; $ps = $_get["UPass"];//1. Connect to database $conn = MySQL _connect ("127.0.0.1", "root", "root");//2. Open the Database mysql_select_db ("game"); new Query//3 = "SELECT * from $sql where uname = ' ". $US." ' and UPass = ' ". $ps. "';"; /4. Execute this query $result = mysql_query ($sql); $n = Mysql_num_rows ($result); Returns the number of results found//5. Close Database Mysql_close ($conn), if ($n >0)//If the number of results is greater than 0, there is a user name and password and passed in the parameters of one to { session_start (); $row = Mysql_fetch_array ($result); Get query result that line $_session["uid"] = $row ["id"]; Returns the ID in the database echo "1"; The server returns the client with a "1"}else{ echo "0"; No results found, return to "0"}?>
The above logic implements the PHP authentication user name and password verification function, want to see the effect can be entered in the browser http://127.0.0.1/testPhp/checkLogin02.php?uname=wang&upass= 123, Login Success page will display 1, login failure page display 0.
Hoho! The server section is finished (this can also be called the server), and the next section begins to write the Cocos2d-x client part we are best at!
Cocos2d-x Network Programming Connect PHP Server Note 2