Php and swf communication SWF and PHP communication (the sendAndLoad method of the LoadVars class is saved, and the XML Parsing method is obtained ):
SWF merge PHP: PHP uses echo to write an xml file, and SWF directly parses the file. (I used to wonder why the blue RSS is in the PHP format. I learned it here to understand it .)
SWF → PHP: swf uses "sendAndLoad" (data_lv.uname = "Zhangsan") to send Variables. php uses $ name =$ _ POST ['uname'] to receive variables.
Note:
1. the message book is actually two small processes. PHP is equivalent to a bridge. We strongly recommend that you write a simple example of both 2 and 3. if the example runs successfully, the message book has completed more than half of it before it starts writing.
2. sendAndLoad can both send variables to php and receive php variables (similar to swf reading text ). You can refer to the volcano tutorial for details.
Start Production (make the above preparations and the following will be well understood ):
1. SWF reads data
① And ② MySQl → PHP → SWF
PHP uses "SELECT" to retrieve from MySQl and then writes xml to SWF for reading.
2. SWF stores data
③ And ④ SWF → PHP → MySQl
SWF uses "sendAndLoad" to PHP, and PHP uses "INSERT" to MySQl.
Solve the garbled text (solve the problem of reading Chinese in the database "???? "):
Select utf8-geeral-ci encoding when you create a database with PhpAdmin.
Before the php file query statement, add: mysql_query ("set names 'utf8 '");
Php modularization (easy to modify later ):
The database connection statement is written in a separate file, such as connectdb. php.
Add require "connectdb. php" to the file where data is written (datatosql. php) and data is read (datatoxml. php.
MySQL troubleshooting function (if the operation is incorrect, it will be easily modified as prompted ):
Mysql_errno (error number); mysql_error (error cause ).
Php date functions (for more details, refer to other help ):
Data ("Ymd, l, H: I"); // 20080608, Sunday
SWF real-time refresh (ensure to read the latest data ):
Swf sends and obtains the real-time variable: data_lv.sendAndLoad ("datatosql. php? N = "+ random (9999), data_lv," post ");
Swf reads real-time xml: myXML. load ("datatoxml. php? N = "+ random (9999 ))
Reference: http://dodomail.javaeye.com/blog/211003