MXML代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onInit()" xmlns="*" layout="absolute" backgroundGradientColors="[#ffffff, #c0c0c0]">
<mx:Script>
<![CDATA[
public function onInit():void
{
userRequest.send();
}
]]>
</mx:Script>
<mx:HTTPService id="userRequest" url="config.php" useProxy="false" method="POST">
<mx:request xmlns="">
<username>{username.text}</username><emailaddress>{emailaddress.text}</emailaddress>
</mx:request>
</mx:HTTPService>
<mx:Form x="22" y="10" width="356">
<mx:HBox>
<mx:Label text="Username"/>
<mx:TextInput id="username"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Email Address"/>
<mx:TextInput id="emailaddress"/>
</mx:HBox>
<mx:Button label="Submit" click="userRequest.send()"/>
</mx:Form>
<mx:DataGrid id="dgUserRequest" x="22" y="128" dataProvider="{userRequest.lastResult.users.user}">
<mx:columns>
<mx:DataGridColumn headerText="User ID" dataField="userid"/>
<mx:DataGridColumn headerText="User Name" dataField="username"/>
</mx:columns>
</mx:DataGrid>
<mx:TextInput x="22" y="292" id="selectedemailaddress" text="{dgUserRequest.selectedItem.emailaddress}"/>
</mx:Application>
PHP代码:
<?php
# 定义数据库资料
Define('DATABASE_SERVER', 'localhost');
Define('DATABASE_USERNAME', 'root');
Define('DATABASE_PASSWORD', '');
Define('DATABASE_NAME', 'flexphp');
# Connect to the database
$mysqli = new mysqli(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME);
mysqli_query($mysqli,"SET NAMES 'utf8'"); //设置UTF8编码
# 判断数据库链接是否OK
if (mysqli_connect_errno()) {
printf("MySQL connect failed: %s\n", mysqli_connect_error());
exit();
}
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']) {
# 添加数据
$query = sprintf("Insert INTO login VALUES ('', '%s', '%s')", quote_smart($_POST['username']), quote_smart($_POST['emailaddress']));
if (!@$mysqli->query($query)) {
printf("'flexphp' login database query insert error: %s\n", $mysqli->error);
$mysqli->close();
exit();
}
}
}
# 显示数据
if (!$result=@$mysqli->query("Select * from login")) {
printf("'flexphp' login database query select error: %s\n", $mysqli->error);
$mysqli->close();
exit();
}
#写入XML文件
$xml_return = "<users>";
while ($user = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$xml_return .=
"<user><userid>".$user['id']."</userid><username>".$user['name']."</username><emailaddress>".$user['mail']."</emailaddress></user>\n";
}
$xml_return.= "</users>";
$mysqli->close();
echo $xml_return;
?>
在调试时候, 由于使用的是PHP内库MYSQLI , 会出现问题, 下面是解决这个问题的方法:
1. 在conf\php.ini中,在vim用 "php_mysql" 搜索到extension=php_mysql.dll,去掉前面的";",同时在下面增加extension=php_mysqli.dll;
2. "extension_dir" 检查路径是否正确;
3. 找到ext/目录,把其中的php_mysql.dll,php_mysqli.dll两个文件Copy to system/system32下(这个地方目录我没找到这样的, 我就COPY TO windows 和 system里面, 也成功了。).
4. 重启服务.切记, 一定要重启服务。
-- phpMyAdmin SQL Dump
-- version 2.9.2
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2008 年 07 月 22 日 06:01
-- 服务器版本: 5.0.27
-- PHP 版本: 5.2.1
--
-- 数据库: `flexphp`
--
-- --------------------------------------------------------
--
-- 表的结构 `login`
--
CREATE TABLE `login` (
`id` int(255) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci NOT NULL,
`mail` varchar(20) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;
--
-- 导出表中的数据 `login`
--
INSERT INTO `login` VALUES (1, '张三', '
[email protected]');
INSERT INTO `login` VALUES (2, '李四', '
[email protected]');
INSERT INTO `login` VALUES (3, '王五', '
[email protected]');
INSERT INTO `login` VALUES (4, '赵六', '
[email protected]');