- //init Joomla Framework
- define( '_JEXEC', 1 );
- define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../..' )); // print this out or observe errors to see which directory you should be in (this is two subfolders in)
- define( 'DS', DIRECTORY_SEPARATOR );
- require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
- require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
- require_once ( JPATH_CONFIGURATION .DS.'configuration.php' );
- require_once ( JPATH_LIBRARIES .DS.'joomla'.DS.'database'.DS.'database.php' );
- require_once ( JPATH_LIBRARIES .DS.'import.php' );
- //DB Connection
- $Config = new JConfig();
- $db_driver = $Config->dbtype; // Database driver name
- $db_host = $Config->host; // Database host name
- $db_user = $Config->user; // User for database authentication
- $db_pass = $Config->password; // Password for database authentication
- $db_name = $Config->db; // Database name
- $db_prefix = $Config->dbprefix; // Database prefix (may be empty)
- // Database prefix (if empty then remove prefixing double underscore)
- $db_prefix = (trim($db_prefix)=="") ? "":$db_prefix;
- $db_connect = mysqli_connect($db_host,$db_user,$db_pass);
- $content_count = 0;
- // CONNECTED! so run a SQL query as per usual
- if (!mysqli_connect_errno()) {
- $query='SELECT COUNT(*) as ArticleCount FROM `'.$db_prefix.'content` WHERE id='.mysqli_real_escape_string($db_connect, $_GET['id']);
- if ($result = mysqli_query($db_connect, $query, MYSQLI_USE_RESULT)) {
- while($obj = $result->fetch_object()){
- $content_count = $obj->ArticleCount;
- }
- }
- }
- echo $content_count;
- mysqli_free_result( $db_connect );
Monday, 15 December 2014
Connect to Joomla database in standalone script
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment