Link to home
Start Free TrialLog in
Avatar of EMB01
EMB01Flag for United States of America

asked on

Can't Query External Database with Joomla

I'm using the following code to delete records from a database; however, it always echos false...  I can't figure out what is going wrong.  The query works fine on it's own, so it must be my implementation.   I'm on joomla 1.5.
$db =&  JDatabase::getinstance($options1);
		$this->setDBO($db);
		if ($db->query($query)) {
		echo "false";
		} else {
		echo "true";
		}
		die;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EMB01

ASKER

Thanks, you're right; it does say true.  However, it doesn't actually delete any records when I look at the database.  Why is it saying true but not executing the query?
Avatar of EMB01

ASKER

Latest event:  When I run the following code, the query returns true but the SETDBO method returns false...


function check_it($function, $whatisit) {
	
		if ($function) {
		echo "the $whatisit function returns TRUE<br />";
		} else {
		echo "the $whatisit function returns FALSE<br />";
		}
	
	}

	function deleteTr($table, $id)
	{
		$options1 = // creds
		$db =&  JDatabase::getinstance($options1);
		$this->check_it($this->setDBO($db), "this->setdbo(db)");
		$query = "delete from `translation` WHERE ORIGTABLE = 'catalog' and TABLEID = 1";
		$this->check_it($db->query($query), "db->query");
		die;
	}

Open in new window

Avatar of EMB01

ASKER

Latest event:  I changed the setdbo to getdbo and now, both methods return true.  However, no data gets deleted... I'm trying to get the delete query to run and delete the corresponding data in the database.
function check_it($function, $whatisit) {
	
		if ($function) {
		echo "the $whatisit function returns TRUE<br />";
		} else {
		echo "the $whatisit function returns FALSE<br />";
		}
	
	}

	function deleteTr($table, $id)
	{
		$options1 = // creds
		$db =&  JDatabase::getinstance($options1);
		$this->check_it($this->getDBO($db), "this->setdbo(db)");
		$query = "delete from `translation` WHERE ORIGTABLE = 'catalog' and TABLEID = 1";
		$this->check_it($db->query($query), "db->query");
		die;
	}

Open in new window

Try changing your query to a select statement and echoing the data. this will verify that you are in fact able to create a valid connection to the external database.

Is the external database on the same web server? or are you trying to connect to a database on a different server (possibly through a firewall)

After that we'll have to verify that the apache user has the rights (permissions) to delete records.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EMB01

ASKER

I found the solution myself.  Thanks for trying, though.