問題描述
我有一個 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.
這篇關于使用 Flex 將表單字段保存在 MySQL 數據庫中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!