Skip to main content
Known Participant
April 11, 2012
Question

SQL Connection using AIR - AS3

  • April 11, 2012
  • 2 replies
  • 5403 views

Hi guys, I'm currently developing a mobile app that have to connect itself to a MySQL database.

Googoling I found this code:

import flash.filesystem.File;

import flash.data.SQLConnection;

import flash.data.SQLStatement;

import flash.net.Responder;

var connection:SQLConnection;

openDatabase();

function openDatabase():void

{

          var dbFile:File = File.applicationStorageDirectory.resolvePath("mySQL.db");

          connection = new SQLConnection();

          connection.addEventListener(SQLEvent.OPEN, onOpen);

          connection.openAsync(dbFile, SQLMode.CREATE);

}

function onOpen(SQLEvent):void

{

          var stat:SQLStatement = new SQLStatement();

          stat.sqlConnection = connection;

          stat.text = "CREATE TABLE IF NOT EXISTS contacts (id INTEGER PRIMARY KEY AUTOINCREMENT, fname TEXT, lname TEXT, phone INTEGER)";

          stat.execute(-1, new Responder(selectItems));

}

function selectItems(SQLEvent):void

{

          trace("Select items!");

}

But there's a problem!

Adobe Flash CS 5.5's compile gives me this error:  "Access to a null or undefined property SQLMode"

...

Is there anyone that can help me?

Thanks!!!

Brandon

This topic has been closed for replies.

2 replies

Participating Frequently
October 25, 2012

I think you miss "import flash.data.SQLMode;"

Participating Frequently
April 12, 2012

SQLConnection and SQLStatement are for using a local SQLite database, not a remote MySQL database.  To get data out of a remote database, you need to call a service, which is written in a server-side language such as PHP, .Net, Java, ColdFusion, etc.

If you had a typo and actually meant a local SQLite database, then I can share some resource recommendations that helped me.

AIR SQLite: an optimization conversa by H. Paul Robertson

http://tv.adobe.com/watch/360flex-conference/air-sqlite-an-optimization-conversa-by-h-paul-robertson/

Working with local SQL databases in AIR

http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118676a5497-7fb4.html

Documentation

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/data/SQLConnection.html