...

View Full Version : flash and remote object



nikos101
10-20-2009, 01:03 PM
I'm using amfphp with flash and have a remote object:

do I need to put the code

$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
mysql_select_db(DB_NAME, $connection) or die(mysql_error());

in every function?


<?php

class Audio{


define("DB_SERVER", "localhost");
define("DB_USER", "audio");
define("DB_PASS", "tat");
define("DB_NAME", "audio");

function listMusic(){


$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
mysql_select_db(DB_NAME, $connection) or die(mysql_error());

$q = "
select 1

";


$result = mysql_query($q, $connection) or $result = mysql_error();


// return $result;
return $result;


}

function checkResetPasswordKey($key){


if (!eregi("^[0-9a-zA-Z]{50}$",$key)) {
return false;
}


$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
mysql_select_db(DB_NAME, $connection) or die(mysql_error());


/* Verify that user is in database */
$q = "SELECT * FROM tbUsers WHERE forgotPassKey = '$key' AND
now() < forgotPassExpiry";
$result = mysql_query($q, $connection);
if (!$result || (mysql_numrows($result) < 1)) {
return false;
}
return $result ;

}

_Aerospace_Eng_
10-20-2009, 01:42 PM
No, just put in there once just after your DEFINES but you will need to pass in the mysql connection link identifier to the function or your queries won't run. In your case
function listMusic($db){

Then replace any instance of $connection in your functions to $db. Now just call it using listMusic($connection) and it will work. Do that for the rest of your functions that run mysql queries.

nikos101
10-20-2009, 02:54 PM
thanks mate, do I need to close the connection somewhere in the class

nikos101
10-20-2009, 03:09 PM
I've done this:


<?php
class Audio{

define("DB_SERVER", "localhost");
define("DB_USER", "audio");
define("DB_PASS", "tat");
define("DB_NAME", "audio");

var $connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
mysql_select_db(DB_NAME, $connection) or die(mysql_error());


function listMusic(){

biut I'm getting an error now:

Parse error: parse error, unexpected T_STRING, expecting T_FUNCTION in C:\Users\Nikos\Documents\Computing\htdocs\amfphp\services\moc\Audio.php on line 4

_Aerospace_Eng_
10-22-2009, 05:54 PM
Post all of Audio.php please.

nikos101
10-22-2009, 08:22 PM
Thanks Aero, I managed to get rid of the errors by doing this:

<?php
define("DB_SERVER", "localhost");
define("DB_USER", "audio");
define("DB_PASS", "tat");
define("DB_NAME", "audio");
class Audio{


var $connection;

function Audio(){

$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum