1. Go to this page and download the library: Download technicalguru/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/ */
$arr = $db->queryList('SELECT * FROM #__devtest', 'MyNamespace\\MyDataClass');
$obj = $db->querySingle('SELECT * FROM #__devtest WHERE uid='.$uid, 'MyNamespace\\MyDataClass');
// Save all object values
$obj->name = 'Some other name';
$db->update('#__devtest', $obj, 'uid='.$obj->uid);
// Save values from array only
$arr = array('name' => 'Another name');
$db->update('#__devtest', $arr, 'uid='.$uid);
class Users extends DAO {
public function __construct($database) {
parent::__construct($database, '#__users', 'MyNamespace\\User');
}
public function findByEmail($email) {
return $this->findSingle(array('email' => $email));
}
public function findByDepartment($department, $order = NULL) {
return $this->find(array('department' => $department), $order);
}
}
class User {
// will not be saved
private $_derivedAttribute;
public function __construct() {
// You can initialize here
}
public function getDerivedAttribute() {
// Have your logic for the attribute here
// or do something completely different
// Return something
return $this->_derivedAttribute;
}
}
class MyDataModel extends \TgDatabase\DataModel {
public function __construct($database) {
parent::__construct($database);
}
protected function init($database) {
// Optional step: call the parent method (it's empty, but could change)
parent::init($database);
// No create your DAOs
$this->register('users', new UserDAO($database));
$this->register('products', new ProductDAO($database));
}
}
class MyFactory implements DaoFactory {
// code omitted for ease of understanding...
public function createDao($name) {
switch ($name) {
case 'users': return new UserDAO($this->database);
case 'products': return new ProductDAO($this->database);
}
return NULL;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.