<?php
/**
* @package Joomla.Cli
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* Joomla 3.2 example CLI script
* Written by: Rene Kreijveld, email [at] renekreijveld.nl
* 05-feb-2014
* Put this script in the /cli folder in the root of your Joomla 3.2 website
* Execute by php <path_to_your_joomla_root>/cli/clidemo_3.2.php
*/
/**
* A command line cron job to trash expired cache data.
*/
// Initialize Joomla framework
const _JEXEC = 1;
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';
// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
/**
* @package Joomla.CLI
* @since 3.0
*/
class Clidemo extends JApplicationCli
{
/**
* Entry point for the script
*
* @return void
*
* @since 3.0
*/
public function doExecute()
{
// Database connector
$db = JFactory::getDbo();
$this->out('Setting query');
// Set SQL query
$query = "SELECT COUNT(*) from #__users";
// Execute query
$db->setQuery($query);
// Get result
$number_of_users = $db->loadResult();
$this->out('Query done');
// Output result
$this->out("We found $number_of_users users.");
}
}
// Instantiate the application object, passing the class name to JCli::getInstance
// and use chaining to execute the application.
JApplicationCli::getInstance('Clidemo')->execute();