Avatar of EMB01
EMB01
Flag 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

JoomlaPHPMySQL Server

Avatar of undefined
Last Comment
EMB01

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Michael701

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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?
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

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

Your help has saved me hundreds of hours of internet surfing.
fblack61
Michael701

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
EMB01

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
EMB01

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