Highlighted

search in a local database (sql) with AS3

Contributor ,
Dec 03, 2015

Copy link to clipboard

Copied

I've got an AS3 code that goes to a php page on a website. That php search in a database (sql) online and send results to my AS3 code.

So I've got 3 files : my project (FLA file), my php file, and my sql file.

Everything is working, but now I would like to do this operation offline (local).

How can I do ?

In my AS3 code I've got :

var urlreq = new URLRequest("http://www.****.com/****/myPHP.php");

urlreq.method = URLRequestMethod.POST; 

var urlVars = new URLVariables(); 

urlVars.theport = "New-York";

urlreq.data = urlVars; 

var loader:URLLoader = new URLLoader(urlreq);

loader.addEventListener(Event.COMPLETE, completed);

loader.dataFormat = URLLoaderDataFormat.VARIABLES;

loader.load(urlreq);

In my php :

$theport = $_POST['theport']; ...

linked to a conn.php file :

$cfg_hote = 'mys****.perso';

$cfg_base = '******';

$cfg_user = '*****';

$cfg_password = '****rhx';

And I've got an sql file uploaded at phpmyadmin.ovh.net

So now, how can I do this operation offline (local) ?

I've tried to change

var urlreq = new URLRequest("http://www.****.com/****/myPHP.php");

to

var urlreq = new URLRequest("myPHP.php");

But it can't find the database on local (sql file);

Thx for your help


EDIT

I've tried to add that to my AS3 code :

import flash.data.SQLConnection;

import flash.data.SQLMode;

import flash.events.SQLErrorEvent;

import flash.events.SQLEvent;

import flash.filesystem.File; 

var conn:SQLConnection = new SQLConnection(); 

conn.addEventListener(SQLEvent.OPEN, openHandler);

conn.addEventListener(SQLErrorEvent.ERROR, errorHandler); 

// The database file is in the application storage directory

var folder:File = File.applicationStorageDirectory;

var dbFile:File = folder.resolvePath("database.sql"); 

conn.openAsync(dbFile, SQLMode.UPDATE); 


function openHandler(event:SQLEvent😞void {

trace("the database opened successfully");

} 


function errorHandler(event:SQLErrorEvent😞void {

trace("Error message:", event.error.message);

trace("Details:", event.error.details);

}

But it can't open the database.sql (trace output : Error #3125: Unable to open the database file)

Anyone see what i can do ?

TOPICS
Development

Views

187

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

search in a local database (sql) with AS3

Contributor ,
Dec 03, 2015

Copy link to clipboard

Copied

I've got an AS3 code that goes to a php page on a website. That php search in a database (sql) online and send results to my AS3 code.

So I've got 3 files : my project (FLA file), my php file, and my sql file.

Everything is working, but now I would like to do this operation offline (local).

How can I do ?

In my AS3 code I've got :

var urlreq = new URLRequest("http://www.****.com/****/myPHP.php");

urlreq.method = URLRequestMethod.POST; 

var urlVars = new URLVariables(); 

urlVars.theport = "New-York";

urlreq.data = urlVars; 

var loader:URLLoader = new URLLoader(urlreq);

loader.addEventListener(Event.COMPLETE, completed);

loader.dataFormat = URLLoaderDataFormat.VARIABLES;

loader.load(urlreq);

In my php :

$theport = $_POST['theport']; ...

linked to a conn.php file :

$cfg_hote = 'mys****.perso';

$cfg_base = '******';

$cfg_user = '*****';

$cfg_password = '****rhx';

And I've got an sql file uploaded at phpmyadmin.ovh.net

So now, how can I do this operation offline (local) ?

I've tried to change

var urlreq = new URLRequest("http://www.****.com/****/myPHP.php");

to

var urlreq = new URLRequest("myPHP.php");

But it can't find the database on local (sql file);

Thx for your help


EDIT

I've tried to add that to my AS3 code :

import flash.data.SQLConnection;

import flash.data.SQLMode;

import flash.events.SQLErrorEvent;

import flash.events.SQLEvent;

import flash.filesystem.File; 

var conn:SQLConnection = new SQLConnection(); 

conn.addEventListener(SQLEvent.OPEN, openHandler);

conn.addEventListener(SQLErrorEvent.ERROR, errorHandler); 

// The database file is in the application storage directory

var folder:File = File.applicationStorageDirectory;

var dbFile:File = folder.resolvePath("database.sql"); 

conn.openAsync(dbFile, SQLMode.UPDATE); 


function openHandler(event:SQLEvent😞void {

trace("the database opened successfully");

} 


function errorHandler(event:SQLErrorEvent😞void {

trace("Error message:", event.error.message);

trace("Details:", event.error.details);

}

But it can't open the database.sql (trace output : Error #3125: Unable to open the database file)

Anyone see what i can do ?

TOPICS
Development

Views

188

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 03, 2015 0
Contributor ,
Dec 04, 2015

Copy link to clipboard

Copied

Have you tried the full path to your local PHP file?

Something like:

var urlreq = new URLRequest("http://localhost/****/myPHP.php");


or


var urlreq = new URLRequest("http://127.0.0.1/****/myPHP.php");

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 04, 2015 0