1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146:
<?php
/**
* Created by PhpStorm.
* User: samtax
* Date: 08/07/2018
* Time: 7:47 AM
*/
/************************************************
* Pixie Query Builder
* for more view @site https://github.com/usmanhalalit/pixie
* call model1->query()->where(...
*
*
*
QB::table('users')->where()
or
User::query()->where()
->where('name', '=', 'usman')
->whereNot('age', '>', 25)
->orWhere('type', '=', 'admin')
->orWhereNot('description', 'LIKE', '%query%')
;
Insert
$data = array(
'name' => 'Sana',
'description' => 'Blah'
);
$insertId = QB::table('my_table')->insert($data);
Get Built Query
$query = QB::table('my_table')->where('id', '=', 3);
$queryObj = $query->getQuery();
$queryObj->getSql();
// Returns: SELECT * FROM my_table where `id` = ?
$queryObj->getRawSql();
// Returns: SELECT * FROM my_table where `id` = 3
E.T.C
*
************************************************/
if(!empty(Config1::DB_NAME)){
// Composer's autoload file included (composer init; required <package name>)
require PATH_LIBRARY . 'pixel/autoload.php';
// Create a connection, once only.
$config = array(
'driver' => Config1::DB_DRIVER, // Db driver
'host' => Config1::DB_HOST,
'database' => Config1::DB_NAME,
'username' => Config1::DB_USER,
'password' => Config1::DB_PASSWORD,
'charset' => 'utf8', // Optional
'collation' => 'utf8_unicode_ci', // Optional
// 'prefix' => 'cb_', // Table prefix, optional
// 'options' => array( // PDO constructor options, optional
// PDO::ATTR_TIMEOUT => 5,
// PDO::ATTR_EMULATE_PREPARES => false,
// ),
);
try{ (new \Pixie\Connection('mysql', $config, 'QB')); } catch (Exception $ex){
$errorMessage = $ex->getMessage();
if(String1::contains('many connections', strtolower($errorMessage))){
Session1::setStatus('Reload Page', 'Multiple connection to Db, Reload to re-connect');
}else{
pre(['<hr/>Database Connection Error..., <hr/>Solution <hr/>[1> Verity Model Query. <hr/>[2> Run Db1::databaseCreate() in "config onDebug(){...}" and Refresh!]<hr/>'. $errorMessage]);
}
};
}
/************************************************
* XCRUD
* call model1->xcrud()->render()
*
* @see http://xcrud.com/
* @see http://xcrud.com/documentation/index.html
*
************************************************/
include PATH_LIBRARY . 'xcrud/xcrud.php';
Xcrud_config::$upload_folder_def = path_asset().'/uploads/xcrud';
//include Page1::getEhexCoreAssetsPath(). '/library/xcrud/xcrud.php';
/************************************************
* Paginator
* example paginate( model1->query() )
* example paginate( [1,2,3...10] )
*
* where Records Could be Any of this
* $records = [1,2,3,4...100]; // Php Array
* $records = $qb->select('*')->from('sample', 'sample'); // Doctrine
* $records = User::select('*')->from('sample'); // Laravel
* $records = QB::select('*')->from('sample'); // Pixel // For Ehex
*
$strana = new \Strana\Paginator();
$paginator = $strana->perPage(10)->make($records);
foreach ($paginator as $item) echo $item['field'] . '<br>';
echo $paginator;
*
* @see https://github.com/usmanhalalit/strana
*
************************************************/
include PATH_LIBRARY . 'paginator/strana/vendor/autoload.php';
function paginate($records, $perPage = 10, $asInfiniteLoad = false, $infiniteLoadConfig = [], $adapterType = null, $config = [], $paginationTemplateClass = \Strana\PaginationTemplate::class) {
//$infiniteLoadConfig = ['loaderDelay' => 600, 'loader' => '<img src="images/loader.gif"/>']
$strana = new \Strana\Paginator();
if($asInfiniteLoad) $strana->infiniteScroll($infiniteLoadConfig);
return $strana->perPage($perPage)->make($records, $paginationTemplateClass, $adapterType, $config);
}