1. Go to this page and download the library: Download joomla/database library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joomla / database example snippets
// Example for initialising a database driver in a custom application class.
use Joomla\Application\AbstractApplication;
use Joomla\Database;
class MyApplication extends AbstractApplication
{
/**
* Database driver.
*
* @var Database\DatabaseDriver
* @since 1.0
*/
protected $db;
protected function doExecute()
{
// Do stuff
}
protected function initialise()
{
// Make the database driver.
$dbFactory = new Database\DatabaseFactory;
$this->db = $dbFactory->getDriver(
$this->get('database.driver'),
array(
'host' => $this->get('database.host'),
'user' => $this->get('database.user'),
'password' => $this->get('database.password'),
'port' => $this->get('database.port'),
'socket' => $this->get('database.socket'),
'database' => $this->get('database.name'),
)
);
}
}
function search($title)
{
// Get the database driver from the factory, or by some other suitable means.
$db = DatabaseDriver::getInstance($options);
// Search for an exact match of the title, correctly sanitising the untrusted input.
$sql1 = 'SELECT * FROM #__content WHERE title = ' . $db->quote($title);
// Special treatment for a LIKE clause.
$search = $db->quote($db->escape($title, true) . '%', false);
$sql2 = 'SELECT * FROM #__content WHERE title LIKE ' . $search;
if (is_array($title))
{
$sql3 = 'SELECT * FROM #__content WHERE title IN ('
. implode(',', $db->quote($title)) . ')';
}
// Do the database calls.
}
$db = DatabaseDriver::getInstance($options);
$iterator = $db->setQuery(
$db->getQuery(true)->select('*')->from('#__content')
)->getIterator();
foreach ($iterator as $row)
{
// Deal with $row
}
$count = count($iterator);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.