Skip to content

Instantly share code, notes, and snippets.

@AlphaNerd
Created January 17, 2016 03:03
Show Gist options
  • Save AlphaNerd/7d131c630ddafae20619 to your computer and use it in GitHub Desktop.
Save AlphaNerd/7d131c630ddafae20619 to your computer and use it in GitHub Desktop.
Connect to Joomla Database from custom PHP file and respond with JSON data
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', '../../../');
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
$database = &JFactory::getDBO();
$sql = "SELECT * FROM `b7j6z_content` WHERE `state` = '1'"; // Select data from DB
$database->setQuery( $sql );
$result=$database->loadAssocList();
header('Content-type: application/json');
header('Access-Control-Allow-Origin: *'); // CORS Settings
$myJSONString = json_encode($result);
echo $myJSONString;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment