all groups > flash actionscript > august 2006 >
You're in the

flash actionscript

group:

using PHP to query MySQL Database


using PHP to query MySQL Database everynewday
8/11/2006 9:09:05 PM
flash actionscript: I'm using PHP to query a MySQL database. In this particular instance, it's
retrieving song names and urls to load into a Media Controller. Here's the
pertinent Actionscript:

thisButton.onRelease = function() {
dbQuery.action = 'getSong';
dbQuery.bandId = 25;
dbQuery.sendAndLoad("http://localhost/mysite/dbquery2.php?ck="+new
Date().getTime(), getSong);
//trace(dbQuery); // traces bandId=25&action=getSong
}

function gotSong(theTarget:LoadVars):Void {
trace(theTarget);
}

var dbQuery:LoadVars = new LoadVars();
var getSong:LoadVars = new LoadVars();
getSong.onLoad = gotSong;

the gotSong function simply traces "true".

The PHP script is attached, if it helps.

<?php
// include the Database classes
require_once('../mysite/database.php');
// escape quotes and apostrophes if magic_quotes_gpc off

foreach($_POST as $key=>$value) {
if (!get_magic_quotes_gpc()) {
$temp = addslashes($value);
$_POST[$key] = $temp;
}
}

if ($_POST['action'] == 'getSong') {
$sql = 'SELECT * FROM songlist WHERE band_id = "'.$_POST['bandId'].'"';
echo getUserList($sql);
}
function getUserList($sql) {
$db = new Database('localhost','siteadmin','r4799608','mysite');
$result = $db->query($sql);
$numrows = $result->num_rows;
$userlist = "total=$numrows";
$counter = 0;
while ($row = $result->fetch_assoc()) {
$userlist .=
'&song_name'.$counter.'='.urlencode(stripslashes($row['song_name']));
$userlist .=
'&song_path'.$counter.'='.urlencode(stripslashes($row['song_path']));
$counter++;
}
$db->close();
return $userlist;
}
?>
Re: using PHP to query MySQL Database everynewday
8/11/2006 9:34:40 PM
AddThis Social Bookmark Button