flash与php:
先把两个代码贴一下:
flash:
var loader:URLLoader = new URLLoader();
var url:URLRequest = new URLRequest("test.php");
url.method = URLRequestMethod.POST;
var values:URLVariables = new URLVariables();
values.message="hello im flash!";
url.data = values;
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE,loaded);
function loaded(e:Event) {
out1.text=loader.data;
//outPut: phpMessage=im php message!&flashMessage=hello im flash!
out2.text=loader.data.phpMessage;
// im php message!
out3.text=loader.data.flashMessage;
// hello im flash!
out4.text=loader.data.dbMessage;
}
loader.load(url);
php:
//这里都是有关数据库的操作
//===================================
Define(’DATABASE_SERVER’, ’localhost’);
Define(’DATABASE_USERNAME’, ’root’);
Define(’DATABASE_PASSWORD’, ’root’);
Define(’DATABASE_NAME’, ’flextest’);
$link=@mysql_connect(DATABASE_SERVER,DATABASE_USERNAME,DATABASE_PASSWORD);
@mysql_select_db(DATABASE_NAME,$link);
$result=@mysql_query("Select * from users");
$user=@mysql_fetch_array($result,MYSQL_ASSOC);
//echo $user[’userid’];
$dbvar=$user[’userid’];
//===================================
//接收flash传进来的数据
$flashData = $_POST[’message’];
//给flash发送的数据
$phpMessage = ’im php message!’;
echo "phpMessage=$phpMessage&flashMessage=$flashData&dbMessage=$dbvar";
?>
代码很简单,不用多解释,其实和asp的没有多大区别的.直接复制到php的路径下即可测试.数据库文件直接在phpMyAdmin下面执行flextest.sql里的sql语句就行了.因为公司禁端口,我不能在线操作我空间的sql的数据库,在线演示地址就没有,等有时间在家里加上.
Flex与php:
先把两个代码贴一下:
Flex:
public function onInit():void
{
userRequest.send();
}
]]>
Php: /* Thanks to Pete Mackie for the code below */
Define(’DATABASE_SERVER’, ’localhost’);
Define(’DATABASE_USERNAME’, ’root’);
Define(’DATABASE_PASSWORD’, ’root’);
Define(’DATABASE_NAME’, ’flextest’);
# Connect to the database
$mysqli = new mysqli(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME);
# Check connection
if (mysqli_connect_errno()) {
printf("MySQL connect failed: %sn", mysqli_connect_error());
exit();
}
# Quote variable to make safe
function quote_smart($value) {
global $mysqli;
# Stripslashes
if (get_magic_quotes_gpc())
$value = stripslashes($value);
# Quote if not integer
if (!is_numeric($value))
$value = $mysqli->real_escape_string($value);
return $value;
}
if (!empty($_POST) && $_SERVER[’REQUEST_METHOD’] == ’POST’) {
if ($_POST[’emailaddress’] && $_POST[’username’]) {
# Add the user
$query = sprintf("Insert INTO users VALUES (’’, ’%s’, ’%s’)", quote_smart($_POST[’username’]), quote_smart($_POST[’emailaddress’]));
if (!@$mysqli->query($query)) {
printf("’flextest’ user database query insert error: %sn", $mysqli->error);
$mysqli->close();
exit();
}
}
}
# Return a list of all the users
if (!$result=@$mysqli->query("Select * from users")) {
printf("’flextest’ user database query select error: %sn", $mysqli->error);
$mysqli->close();
exit();
}
$xml_return = "
while ($user = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$xml_return .=
"
}
$xml_return.= "
$mysqli->close();
echo $xml_return;
?>
这里的代码就是Adobe phpria sdk里的一个实例. 如果想要全部源码的请留下邮箱,我来发.flex与php的就不说了,直接把php的代码化成asp代码就行了,和flash的一道理了.