I am using Joomla 1.5. I've produced a custom ingredient that pulls data from the database perfectly. I initialize the database during my primary component file such as this:

$db =& JFactory::getDBO();

However , I've got a jQuery autocomplete wordpress plugin on my small component page which makes calls to some PHP file from the component folder. That PHP file searches the database for matching results however i can't perform the query because I can not call $db =& JFactory::getDBO(); since this is a custom PHP page and that i can't access these characteristics with no references.

Can anybody assist me to to call Joomla functions during my custom file ?

Thanks.

I would suggest not calling another PHP file and rather while using raw view format inside your component. To get this done, produce a view inside your component for that data that jQuery is going to be tugging. For discussion, we'll refer to this as view autocomplete. Setup the autocomplete view while you would every other, only using view.raw.php instead of view.html.php. Then inside your JavaScript, call index.php?option=com_yourcomponent&view=autocomplete&format=raw. This HTTP call is only going to return that which you output inside your view.

Should you absolutely must run an exterior PHP file, have a look at developing a stand-alone application while using Joomla! Framework: http://docs.joomla.org/How_to_create_a_stand-alone_application_using_the_Joomla%21_Framework This really is enough code to drag in JFactory and also the database connection. Only make use of this if you will need to: otherwise, you're just creating another access point in to the Joomla! application that you may have to keep and secure.

You might find Louis Landry's publish on doing JSON useful: http://groups.google.com/group/joomla-dev-cms/browse_thread/thread/5ac0b49c0f458b1a

I additionally blogged relating to this subject lately: http://www.designvsdevelop.com/the-way-not-to-do-javascript-in-joomla/

I'd make use of the JLoader class to incorporate exterior PHP files and classes to joomla.

        

JLoader::register( 'classname', dirname(__FILE__).DS.'classfoldername'.DS.'classfile.php');

This could range from the class making it ready to be used:

$theClass = new classname();