Adobe Flex 到数据库插入、更新?
我很难通过 zend php 将 Flex 连接到 MySql。我看到了几个使用 HTTP 服务的示例。我的问题如下
1)我只做一个简单的插入和更新,只有三个表。那么我应该使用所有这些 Zend AMF 来实现这一目标吗? 2)否则使用 HTTPService 怎么样?
使用 zend AMF 进行显示是最简单的操作,但是当我尝试插入值时,我迷失了。
我有一个 php 文件 vo.php 来存储数据库字段变量,但我无法在主 php 文件中使用 require_once 函数
这是 vo.php
class vo {
public $id;
public $username;
public $symptom;
public $number_of_times_tested;
public $original_image;
public $sequence_of_actions;
public $customized_image;
public $percieved_image;
}
这是病人服务文件
//require_once 'vo.php';
class patientService {
var $username = "root";
var $password = "";
var $server = "localhost";
var $port = "3306";
var $databasename = "patient";
var $tablename = "records";
var $connection;
public function __construct() {
$this->connection = mysqli_connect(
$this->server,
$this->username,
$this->password,
$this->databasename,
$this->port);
$this->throwExceptionOnError($this->connection);
}
public function getpatient() {
$stmt = mysqli_prepare($this->connection,
"SELECT
records.id,
records.username,
records.symptom,
records.number_of_times_tested,
records.original_image,
records.sequence_of_actions,
records.customized_image,
records.percieved_image
FROM records");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->username,
$row->symptom, $row->number_of_times_tested, $row->original_image, $row->sequence_of_actions, $row->customized_image, $row->percieved_image
);
while (mysqli_stmt_fetch($stmt)) {
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->username,
$row->symptom, $row->number_of_times_tested, $row->original_image, $row->sequence_of_actions, $row->customized_image, $row->percieved_image
);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
/* create a entry for database patient
*/
public function createPatient($item) {
$stmt = mysqli_prepare($this->connection,
"INSERT INTO patient (
id,username,symptom,number_of_times_tested,original_image,sequence_of_actions,
customized_image,percieved_image)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_bind_param($stmt, $item->id , $item->username, $item->symptom,$item->number_of_times_tested,$item->original_image,
$item->sequence_of_actions, $item->customized_image, $item->percieved_image
);
$item->id = '5';
$item->username = 'abhilash';
$item->symptom = 'retina pigmentosa';
$item->number_of_times_tested = '3';
$item->original_image = 'img';
$item->sequence_of_actions = 'l1l2l2lr3';
$item->customized_image = 'img';
$item->percieved_image = 'img';
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
谁能提供一个详细示例的链接?这样我可以更好地参考和理解吗?
I'm having tough time connecting flex to MySql through zend php. I saw a couple of examples using HTTP service. My question is as follows
1) I'm doing a simple insert and update only, just three tables. So should i use all those Zend AMF to achieve this?
2) Else what about using HTTPService?
The display was easiest operation using zend AMF, but when i tried inserting values, i was lost.
I'd a php file vo.php to store database field variables, but i could not use require_once function in main php file
This is vo.php
class vo {
public $id;
public $username;
public $symptom;
public $number_of_times_tested;
public $original_image;
public $sequence_of_actions;
public $customized_image;
public $percieved_image;
}
this is patientService file
//require_once 'vo.php';
class patientService {
var $username = "root";
var $password = "";
var $server = "localhost";
var $port = "3306";
var $databasename = "patient";
var $tablename = "records";
var $connection;
public function __construct() {
$this->connection = mysqli_connect(
$this->server,
$this->username,
$this->password,
$this->databasename,
$this->port);
$this->throwExceptionOnError($this->connection);
}
public function getpatient() {
$stmt = mysqli_prepare($this->connection,
"SELECT
records.id,
records.username,
records.symptom,
records.number_of_times_tested,
records.original_image,
records.sequence_of_actions,
records.customized_image,
records.percieved_image
FROM records");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->username,
$row->symptom, $row->number_of_times_tested, $row->original_image, $row->sequence_of_actions, $row->customized_image, $row->percieved_image
);
while (mysqli_stmt_fetch($stmt)) {
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->username,
$row->symptom, $row->number_of_times_tested, $row->original_image, $row->sequence_of_actions, $row->customized_image, $row->percieved_image
);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
/* create a entry for database patient
*/
public function createPatient($item) {
$stmt = mysqli_prepare($this->connection,
"INSERT INTO patient (
id,username,symptom,number_of_times_tested,original_image,sequence_of_actions,
customized_image,percieved_image)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_bind_param($stmt, $item->id , $item->username, $item->symptom,$item->number_of_times_tested,$item->original_image,
$item->sequence_of_actions, $item->customized_image, $item->percieved_image
);
$item->id = '5';
$item->username = 'abhilash';
$item->symptom = 'retina pigmentosa';
$item->number_of_times_tested = '3';
$item->original_image = 'img';
$item->sequence_of_actions = 'l1l2l2lr3';
$item->customized_image = 'img';
$item->percieved_image = 'img';
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
Can anyone give a link to good detailed example? So i can refer and understand better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTTPService 用于请求 Flex 内部的任何类型的 HTTP 资源。如果您愿意,您可以设计自己的基于 JSON 或 XML 的 Web 服务,它将在您的表上执行所需的操作。该策略与前端无关,例如,如果您选择切换前端技术,从 Flex 到 HTML/Ajax,则无需对后端进行任何更改。
另一个解决方案是使用 Zend_AMF 来通过 AMF 从 Flex 与 PHP 对象直接交互。
我一直更喜欢使用第一个解决方案(没有比我更好地理解我所做的事情更有趣的原因),但如果您计划仅使用 Flex 前端,那么第二个解决方案应该会给您带来一些生产力提升。
HTTPService is here to be used to request any kind of HTTP ressource inside of Flex. If you want you can design your own JSon or XML based webservice that will do the needed operation on your table. This strategy front end independent, if you choose to switch front-end techno, from Flex to HTML/Ajax, for instance you won't have to do any change on your backend.
The other solution is to use Zend_AMF to enable direct interaction with your PHP object from Flex through AMF.
I've always prefered to use the first solution (with no more interesting reasons than I better understood what I do), but the second one should give you some productivity gain if you plan do to a flex only front end.