PDA

View Full Version : mySQL, PHP and Flash



alpharaven
March 5th, 2007, 10:20 AM
I have been looking for a good tutorial on how to create a DB that flash can pull info from it. I want this particular client to be able to update their image gallery and news section. I've done some searching but cant find anything that makes this whole process seem easy. Everything that I've seen seems too complicated for what I need to do. Can anyone please help......Thanks

duncanhall
March 5th, 2007, 10:29 AM
Try these:

http://www.amfphp.org
http://www.kirupa.com/forum/showthread.php?t=247050

deletedUser2352352
March 5th, 2007, 11:10 AM
flash sendandload

send vars to php and get the php to output xml.

thats what i'm planing on doing.

duncanhall
March 5th, 2007, 11:17 AM
bugboy - If you are just using XML as your data source then your method is definately one that can work well. But if, as alpharaven does, you wish to use a database rather than XML to store data, outputting to XML is simply an extra, completely unneccessary step.

With amfphp you can talk directly to your database (albeit via a 'service' on your server). You can send and receive variables to and from flash without any breakdown of structure. For instance a PHP array can be sent to Flash and it's ready to interact with as an actionscript array. This, I think, is amazing.

deletedUser2352352
March 5th, 2007, 11:43 AM
no i'm sending data via post to the php page which accesses a database then returning xml. Its dead simple and works a charm.

I understand what your saying ducanhall but i found tha amfphp really confusing to use.

duncanhall
March 5th, 2007, 11:56 AM
If it works for you, I'm not gonna knock it. =)

But I'd defiantely recommend spending some time looking at amfphp though. If you have the PHP knowledge to do what you specified above, than that's easily enough to allow you to set up amfphp.

I'm guessing at the moment, once the data is output from your DB, you have a pretty hefty PHP script which formats it into XML. I imagine you then have some arduous code in Flash that undoes that XML back into real data. As you can see, those last two steps are a "no brainer" when it comes to deciding what to get rid of.

There's a pretty good tutorial here: http://www.flash-db.com/Tutorials/hello/flashamfphp.php

deletedUser2352352
March 5th, 2007, 12:12 PM
With the php i just loop through the database with the classes i've set up for that into xml.

for example:


<?php
require_once('includes/DbConnector.php'); // database connection class
$connector = new DbConnector(); // create object
$result = $connector->query('SELECT * FROM table');
while ($row = $connector->fetchArray($result)){
$holdArray[] = $row;
}
$xml_output = '<?xml version=\"1.0\"?>';
$xml_output .= '<myXML>';
foreach ($holdArray as $arr) {
$xml_output .='<entry id="'.$arr['1'].'">'.$arr['2'].'</entry>';
}
$xml_output .= '<myXML>';
echo $xml_output;
?>



With the flash i just loop through the xml into an array and then use the array.

I really can see where your coming from and i can see the benifits but at the mo it doesn't seem right to me gut instincts.

duncanhall
March 5th, 2007, 12:21 PM
*Stuffs amfphp down your throat*

YOU'LL USE THIS AND YOU'LL LIKE IT, OK?!!!



Haha, fair play, you seem to have a good system set up.

deletedUser2352352
March 5th, 2007, 12:33 PM
ha ha ha i'll give it a go. :)

alpharaven
March 5th, 2007, 08:53 PM
After reading all of these posts...lol. I am still confused by it all. Will the client be able to change existing content and add to it as well?

deletedUser2352352
March 6th, 2007, 03:46 AM
As long as you have a backend system in place that you allow the client access to change information then yes.

JoshuaJonah
March 6th, 2007, 09:33 AM
You know it's also possible to get the data directly from php without AMF too. Thats what i do.

duncanhall
March 6th, 2007, 09:57 AM
Sounds exciting. Can I ask how? Have you built your own method of managing requests from flash or is it something quite simple I could try myself?

JoshuaJonah
March 6th, 2007, 10:20 AM
it's just sending strings directly to LoadVars with php.

deletedUser2352352
March 6th, 2007, 10:53 AM
which is what i do. as well

duncanhall
March 6th, 2007, 11:01 AM
Joshua - how do you handle the data that comes back from the database?

JoshuaJonah
March 6th, 2007, 11:14 AM
use php to for a long string of variables and values, then load it into a multidimensional array or object in flash

JoshuaJonah
March 6th, 2007, 01:27 PM
because clients dont want to connect with an ftp client and edit a text file. They would rather pay you to do it. They want a CMS or something idiot proof.

Digitalosophy
March 6th, 2007, 01:51 PM
use php to for a long string of variables and values, then load it into a multidimensional array or object in flash

We use the exact same thing here at work only using ASP for the backend. Hardest part I've had with it is parsing the data.

duncanhall
March 7th, 2007, 05:59 AM
Hardest part I've had with it is parsing the data.

That was my reason for using / promoting amfphp. I can't see an easier method than being able to get a recordset from your DB and pass it srtaight to flash without any need to parse data.

Digitalosophy
March 7th, 2007, 09:12 AM
That was my reason for using / promoting amfphp. I can't see an easier method than being able to get a recordset from your DB and pass it srtaight to flash without any need to parse data.

Yea amfphp really makes it a dream, I was impressed. Problem is we use ASP and I don' think there is an amfasp :lol:

duncanhall
March 7th, 2007, 10:03 AM
Ah, you'd be surprised...

http://amfnet.openmymind.net/default.aspx

=)

Digitalosophy
March 7th, 2007, 10:06 AM
haha well look at that, only thing is that is .net which we aren't ready to convert all our sites to .net yet. But that is something that's been up for disussion for a while now.

Babaloo
September 5th, 2007, 02:29 PM
It would be really really nice to see a Kirupa tutorial / post or article with flash amfphp php mysql for real beginners.
The ones I've looked up so far (sephiroth and flash-db) were too advanced for me... Specially on the php and AS2 classes and methods...