When I first started this message, I didn't even have access to MySQL or PHP. After the pain of finding information and learning, depressed one weeks after the completion of my simple message book. There is no better online PHP message-related tutorials, I downloaded n multi-source files are foggy, and many of the code is written on the MC. Or maybe there's a good tutorial I didn't find, but anyway, I'm going to swim here now. Objective :
Use Flash+php+mysql to make a simple message book.
Configure the Environment :
The first thing you must do is configure the appropriate environment. I downloaded the configuration Environment Kit package, a fool-style method, easy to install, more suitable for me. Download Address: http://phpnow.org/download.html (including: Apache, PHP, MySQL, Zend Optimizer, PhpMyAdmin, Eaccelerator)
The folder is described below (init.cmd installation; Pncp.cmd Control Panel. ):
Figure 1
Apache folder: PHP server (similar to IIS).
mysql-5.0.15b folder: MySQL database server.
Data folder: The site database is stored. (The database of the message book is stored in this, backstage)
Bin folder: Files inside to operate the database (DOS mode)
Php-5.2.6-win32 folder: PHP's library of functions, explained by Apache.
Zendoptimizer folder: accelerates PHP execution.
Htdoc (or WWW): Store Web page files. (the page file of the message book is placed here, the front desk)
phpMyAdmin folder: Operating database (Windows mode)
Note :
1, the installation will prompt you to enter the MySQL database password, here the password to "sun" for example. (User name "root")
Figure 2
2, the browser input "http://127.0.0.1" Display configuration related information, you can enter the MySQL password for connection testing.
Figure 3
3, the Site Directory index is closed by default, with the console to open it, facilitate the post-site (message board) testing.
Figure 4
Figure 5
Knowledge Preparation:
1, first introduce how to use PHP to connect the database (database user name "root", the password "sun", there is a library "Myguestbook")
Figure 6
2, PHP and MySQL communication (SQL statement: INSERT, select fetch):
Php←mysql:select * from Myguestbook;
Php→mysql:insert into Myguestbook (name,comment) VALUE ("Zhang San", "This is a message");
3, SWF and PHP communication (Loadvars Class of Sendandload method, parse XML way to take):
swf←php:php writes an XML file with Echo, and the SWF parses the file directly. (I used to wonder why the blue RSS is in PHP format and learned here.) )
SWF→PHP:SWF uses "Sendandload" (data_lv.uname= "Zhang San") to send variables, and PHP receives them with $name=$_post[' uname '.
Note :
1, the message is actually the two small process, PHP equivalent to a bridge. It is strongly recommended to write a simple example of 2 and 3, the example runs successfully, the message has not started to write the more than half has been completed.
2. Sendandload can either send variables to PHP or receive PHP variables (similar to SWF read text). Can see the volcano's tutorial, very detailed.
Start making (do the preparation above, the following will be well understood):
Figure 7
1. SWF reads data
① and ②mysql→php→swf
PHP takes "select" from MySQL and writes it as XML to read to SWF.
Figure 8
2. SWF Storage Data
③ and ④swf→php→mysql
SWF uses "Sendandload" to give php,php "INSERT" to MySQL.
Figure 9 Click to enlarge
After the completion of:
Figure 10
Other precautions:
Fix garbled (the Chinese read out in the database is "????" ):
Select the "utf8-geeral-ci" encoding when creating a database with Phpadmin.
In the PHP file before the query statement, plus: mysql_query ("Set names ' UTF8 '");
PHP modularity (easy to modify later):
The statements that connect to the database are written in a separate file, such as connectdb.php.
Write Data (datatosql.php) and read data (datatoxml.php) in the file Plus: Require "connectdb.php" can be.
MySQL Troubleshooting function (if the operation is wrong, according to the prompt can be easily modified):
Mysql_errno (Error number); Mysql_error (cause of error).
PHP's Date function (for more details, refer to other help):
Data ("Ymd,l,h:i"); 20080608,sunday,09:28
SWF Real-time refresh (guaranteed to read the latest data):
SWF sends and gets real-time variables: data_lv.sendandload ("datatosql.php?n=" +random (9999), DATA_LV, "post");
SWF reads real-time Xml:myXML.load ("datatoxml.php?n=" +random (9999))