Created
January 17, 2016 03:03
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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