Director — MySQL communication

As a per­son whose expe­ri­ence in pro­gram­ming is con­nect­ed main­ly to Direc­tor and Lin­go, I often searched but nev­er found a com­par­a­tive­ly sim­ple and clear tuto­r­i­al that describes step by step what is nec­es­sary to do in order to get an appli­ca­tion, which com­mu­ni­cates in a duplex way to a MySQL data­base. Here I will try to explain how to achieve this on your local machine, under Win­dows — if the read­er has already read such tuto­ri­als he or she may skip the fol­low­ing lines.
Gen­er­al­ly, to get this you need: a web serv­er, a MySQL serv­er, a data­base, a Direc­tor appli­ca­tion, as well as some­thing for the com­mu­ni­ca­tion between the appli­ca­tion and the MySQL serv­er. In our case this will be PHP.
For our con­ve­nience and quick­ness, in this tuto­r­i­al we will use XAMPP and thus we will get in one fling a web serv­er ( work­ing with PHP4 and PHP5 ) and MySQL server.


1. Down­load and install XAMPP. Leave all the set­tings by default. After the instal­la­tion process is fin­ished a direc­to­ry “c:\xampp\” must have been created.

2. In the direc­to­ry “C:\xampp\htdocs\” cre­ate anoth­er direc­to­ry called “Direc­torTest\”. After that down­load this file

Direc­tor Test Data­base (9705 downloads) 

and save it in the directory.

3. Choose Start > Pro­grams > XAMPP For Win­dows > XAMPP Con­trol Pan­el and start Apache and MySQL. Now you have a work­ing web serv­er, PHP and a MySQL serv­er on your local machine. Test them by open­ing the brows­er and try on this address: “http://localhost”. You should see the ini­tial screen of “XAMPP for Win­dows” — choose a language.

4. Choose PHP­MyAd­min, write “direc­tortest” in Cre­ate new data­base text field and click Cre­ate.

5. Click Import tab, after that click Choose File but­ton and select “DirectorTestDatabase.sql” file, down­loaded and saved in step 2
( The full path to it should be “c:\xampp\htdocs\DirectorTest\DirectorTestDatabase.sql” ) Click GO but­ton. You should see a notice that says “Import has been suc­cess­ful­ly fin­ished, 16 queries exe­cut­ed.” Now you have a data­base. There is a table in this data­base, called “address­book”, which con­tains the fol­low­ing columns: id, first_name, last_name, e_mail, phone_number

6. Now here comes the Direc­tor appli­ca­tion. To spare time, there is an already fin­ished one — down­load it and save it in “c:\xampp\htdocs\DirectorTest\”

Address Book (2529 downloads) 

7. Start AddressBook.dir in Direc­tor. You will prob­a­bly see an alert:

"Warning:  require_once(DiDal/DiDalHttpHandler.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in C:\xampp\htdocs\DirectorTest\didal.php on line 2 Fatal error:"

8. Now we will intro­duce DIDAL — Direc­tor Data Access Lay­er — to the whole pic­ture. With Direc­tor still opened, down­load and unzip it in the already famil­iar direc­to­ry “c:\xampp\htdocs\DirectorTest\”.

DiDAL (7549 downloads) 

After unzip­ping, the direc­to­ry should look as follows:


Start the “Address­Book” appli­ca­tion again — now it should look like this:


The fol­low­ing is the rec­om­mend­ed way to work with DIDAL:
1. We care­ful­ly con­sid­er the inter­ac­tions between the appli­ca­tion and the MySQL serv­er and on this basis we define “com­mands” with para­me­ters. In this par­tic­u­lar case the inter­ac­tions of the appli­ca­tion with the serv­er can be reduced to: extract­ing all the records from the table, called “address­book”, adding new records to “address­book” table and delet­ing records from “address­book” table. In this case, our com­mand names are suf­fi­cient­ly descrip­tive — “getAll­Con­tacts”, “cre­at­e­New­Con­tact” and “delete­Con­tact­ById”.
2. We spec­i­fy the data (para­me­ters) need­ed for a com­mand to be exe­cut­ed. For exam­ple, the exe­cu­tion of “getAll­Con­tacts” com­mand does not need any addi­tion­al data sup­plied by the appli­ca­tion. Obvi­ous­ly, “cre­at­e­New­Con­tact” needs data to be record­ed in “address­book” table. The exe­cu­tion of “delete­Con­tact­ById” is impos­si­ble with­out sup­ply­ing “id” of the record which must be deleted.
3. After spec­i­fy­ing all this, we open “didal-config.xml” file, which should be in “c:\xampp\htdocs\DirectorTest\DiDal\didal-config.xml”. Pay atten­tion to this line:

<connection host="localhost" username="root" passwd="" dbname="directortest" encoding="cp1251" />

This assigns para­me­ters to the con­nec­tion with the database.
In sec­tion, we define our com­mands as follows:

<command name="yourCommandName" table="databaseTableName">

So, we see that in this file the two com­mands — getAll­Con­tacts and cre­at­e­New­Con­tact are defined. delete­Con­tact­ById is not defined. That is why when the exe­cu­tion is start­ed the fol­low­ing alert is generated:

"Fatal error:  Call to a member function getTable() on a non-object in C:\xampp\htdocs\DirectorTest\DiDal\DiDalRequest.php on line 55"

Here we define delete­Con­tact­ById command:

		<command name="deleteContactById" table="addressbook">
				DELETE FROM addressbook WHERE id = :rowid

Notice that para­me­ters are writ­ten with “:” at the begin­ing. We define the com­mand as 

IO.registerCommand( "deleteContactById", [ #rowid ] )

in the appli­ca­tion. But in the con­fig­u­ra­tion file #rowid para­me­ter is writ­ten as :rowid
Have in mind that “table” attribute in 

<command name="deleteContactById" table="addressbook">

line will be con­vert­ed to a sym­bol when the result of the com­mand is returned. It is nec­es­sary this attribute to be present, but it is not nec­es­sary for it to cor­re­spond to the name of the table, which we ref­fer in the SQL request. 


At the end we must cre­ate a pro­jec­tor in order to have a work­ing desk­top appli­ca­tion. For this pur­pose you have to cre­ate direc­to­ry c:\xampp\htdocs\DirectorTest\Xtras\
Copy the fol­low­ing files in it:


which can be found in the instal­la­tion direc­to­ry of Direc­tor ( for exam­ple “C:\Program Files\Macromedia\Director MX 2004\” )
Copy “NetLingo.x32”, “INetURL.x32”, “NetFile.x32” files in Xtras directory.
“INetURL.x32” and “NetFile.x32” are in “Your root Direc­tor Folder\Configuration\Xtras\Core\Net Support\”
“NetLingo.x32” can be found in “Your root Direc­tor Folder\Configuration\Xtras\Scripting\”
In Direc­tor, choose from the main menu File > Publish…
In “Select Out­put direc­to­ry for AddressBook.exe” dia­logue box select “C:\xampp\htdocs\DirectorTest\” direc­to­ry and click Select Fold­er.

Here is a work­ing demo:

Direc­tor-DiDal-MySQL demo

Great stuff dude. Sounds real­ly amaz­ing to me…

Thanks, useful/clear explanation

Scott Whitney

I use Direc­tor MX 2004 — nev­er had a real rea­son to upgrade.
I found one CRITICAL bug that was dri­ving me bonkers.
In the PHP code to con­vert the mySQL query results to a list, I found that I MUST use sin­gle quotes around strings. Dou­ble quotes work fine from the mes­sage win­dow, but in run­time Direc­tor gets con­fused and breaks down unless I use sin­gle quotes.
Thanks TONS for your out­stand­ing tuto­r­i­al. It real­ly helped me switch from using the Roset­ta XTRA with MSAc­cess to mySQL both online and on a local flash drive.

Scott Whitney

Just to clar­i­fy what I mean by using sin­gle quotes:
echo “[“; // this works fine in the mes­sage win­dow, but not in runtime
echo ‘[‘ // this works in runtime