使用 Flex 将表单字段保存在 MySQL 数据库中

2021-11-12 00:00:00 mysql apache-flex flexbuilder flex4 flex4.5

我有一个 MySQL 数据库,我创建了一个数据库并将其命名为PERSONDB".在该数据库中,我创建了一个表并将其命名为 Person.该表有 3 个字段.id,name,age.

I have a MySQL database, and i created a DB and named it 'PERSONDB'. Within that DB, i have created a table and named it Person. This table has 3 fields. id,name,age.

现在我需要将一些值从我的 flex 网站保存到我创建的 mySQL 'PERSONDB'.

Now i need to save some values from my flex website to the mySQL 'PERSONDB' that i created.

我如何在 Flex (Flax builder 4.6) 中执行此操作

How can i do this in Flex (Flax builder 4.6)

注意:我在 Flex 项目中添加了 2 个字段名称和年龄,当用户单击按钮时,我需要将这些值保存在数据库中.我该怎么做.

Note: I have added 2 fields name and age, in the Flex project and when the user clicks on the Button i need those values to be saved in the DB. how can i do this.

推荐答案

asSQL ( http://code.google.com/p/assql/ ) 是使用 mySQL 的好方法.它允许从 AIR 或基于 Web 的任何应用程序直接访问 mySQL.我在编码中经常使用它,因此我不必编写 Java 或 PHP 作为后端,除非有充分的理由安装后端.

asSQL ( http://code.google.com/p/assql/ ) is a good approach to using mySQL. It allows for direct access to mySQL from any application either in AIR or web based. I use this pretty regularly in my coding so I don't have to write a Java or PHP as a back end unless there is a good reason to have a back end in place.

好的,这是我使用的代码:

OK, here is the code I use:

    <assql:MySqlService id         ="DB"
                        hostname   ="localhost"
                        username   ="user"
                        password   ="password"
                        database   ="db"
                        autoConnect="true"
                        connect    ="handleConnected(event)"
                        sqlError   ="handleError(event)"/>


        private function getSelectedData() : void
        {
            DB.send("SELECT * from table WHERE number = '" + number.text + "'");
        }

仅此而已.顶部设置连接,位于代码部分.其余部分在 (ActionScript) 部分.当然,也可以直接在 ActionScript 中完成,但是这个解决方案使用了 MXML.

That's all there is too it. The top part sets up the connection and is in the section of the code. The rest is in the part (ActionScript). Of course, it can be done in straight ActionScript as well, but this solution used MXML.

相关文章