upgrade first session to flightphp

This commit is contained in:
2026-08-19 17:22:07 +07:00
parent 36395c2b55
commit 27ebdca49b
31 changed files with 1383 additions and 7659 deletions
+122 -75
View File
@@ -6,125 +6,172 @@
Desc. : Class Query database
Created By : Siau Pheng ([email protected]).
Created Date : February 2nd, 2007.
Last Modified : December 17th, 2023.
Last Modified : August 14th, 2026.
(c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
//OK
declare(strict_types=1);
namespace siaupheng\webapp\DB;
use flight\Engine;
use flight\Session;
use flight\database\SimplePdo;
use siaupheng\webapp\Web\Param;
final class SQL {
private $__ttable = "";
private $__afield = array();
private $__avalue = array();
private $__anomor = array();
private $__twhere = "";
protected $__db = null;
private string $_ttable;
private array $_afield = [];
private array $_awhere = [];
protected Engine $app;
protected SimplePdo $db;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
public function __construct(?Engine $app = null){
$this->app = (empty($app) === true) ? \Flight::app() : $app;
$this->db = $this->app->db();
}
public function SafeSQL($ttext = "") {
return $this->__db->SafeSQL($ttext);
public function SafeSQL($ttext = "") {//delete
return $ttext;
}
public function set_table($ttable = "") {
$this->__ttable = $ttable;
public function set_table(string $table = ""): void {
$this->_ttable = $table;
}
public function add_param($tparam = "", $tvalue = null, $bnomor = false) {
$this->__afield[] = $tparam;
$this->__avalue[] = (is_null($tvalue) && isset($_REQUEST[$tparam])) ? $this->__db->SafeSQL($_REQUEST[$tparam]) : $tvalue;
$this->__anomor[] = $bnomor;
public function add_param(string $param = "", string|int|null $value = null, bool $nomor = false): void {
$this->_afield[] = [
'field' => $param,
'value' => (is_null($value) && !empty(Param::Get($param))) ? Param::Get($param) : $value,
'numbe' => $nomor,
];
}
public function add_param_date($tparam = "", $tvalue = null) {
$this->__afield[] = $tparam;
$this->__avalue[] = tgl_sql2str((is_null($tvalue) && isset($_REQUEST[$tparam])) ? $this->__db->SafeSQL($_REQUEST[$tparam]) : $tvalue);
$this->__anomor[] = false;
public function add_param_date(string $param = "", string|null $value = null): void {
$this->_afield[] = [
'field' => $param,
'value' => tgl_sql2str((is_null($value) && !empty(Param::Get($param))) ? Param::Get($param) : $value),
'numbe' => false,
];
}
public function add_param_stamp($tparam = "DateStamp") {
$this->__afield[] = $tparam;
$this->__avalue[] = "NOW()";
$this->__anomor[] = true;
public function add_param_stamp(string $param = "DateStamp"): void {
$this->_afield[] = [
'field' => $param,
'value' => 'NOW()',
'numbe' => true,
];
}
public function add_param_unix() {
$this->__afield[] = "Unix";
$this->__avalue[] = user_unix();
$this->__anomor[] = false;
public function add_param_unix(): void {
$this->_afield[] = [
'field' => 'Unix',
'value' => user_unix(),
'numbe' => false,
];
}
public function add_param_userid($tparam = "UserID") {
$this->__afield[] = $tparam;
$this->__avalue[] = user_id();
$this->__anomor[] = false;
public function add_param_userid(string $param = "UserID"): void {
$this->_afield[] = [
'field' => $param,
'value' => user_id(),
'numbe' => false,
];
}
public function add_where_unix() {
$this->__twhere .= (($this->__twhere=="") ? " WHERE " : " AND ") . "(Unix='".user_unix()."')";
public function add_where_unix(): void {
$this->_awhere[] = [
'field' => 'Unix',
'value' => user_id(),
'numbe' => false,
];
}
public function add_where_date($tfield = "", $tvalue = null) {
$tvalue = ($tvalue == null) ? "0000-00-00" : tgl_sql2str($tvalue);
$this->add_where($tfield, $tvalue);
public function add_where_date(string $field = "", string|null $value = null): void {
$this->_awhere[] = [
'field' => $field,
'value' => (is_null($value)) ? '0000-00-00' : tgl_sql2str($value),
'numbe' => false,
];
}
public function add_where($tfield = "", $tvalue = null) {
$__tvalue = (is_null($tvalue) && isset($_REQUEST[$tfield])) ? $this->__db->SafeSQL($_REQUEST[$tfield]) : $tvalue;
$this->__twhere .= (($this->__twhere=="") ? " WHERE " : " AND ") . "(".$tfield."='".$__tvalue."')";
public function add_where(string $field = "", string|int|null $value = null, bool $nomor = false): void {
$this->_awhere[] = [
'field' => $field,
'value' => (is_null($value) && !empty(Param::Get($field))) ? Param::Get($field) : $value,
'numbe' => $nomor,
];
}
public function clear_param() {
$this->__afield = array();
$this->__avalue = array();
$this->__anomor = array();
public function clear_param(): void {
$this->_afield = [];
}
public function clear_where() {
$this->__twhere = "";
public function clear_where(): void {
$this->_awhere = [];
}
public function InsertDB() {
$tsql = "INSERT INTO ".$this->__ttable." (";
$tfield = "";
$tvalue = "";
for ($i=0; $i<count($this->__afield); $i++) {
$tfield .= ",".$this->__afield[$i];
$tvalue .= ",".(($this->__anomor[$i])?"":"'").$this->__avalue[$i].(($this->__anomor[$i])?"":"'");
public function InsertDB(): void {
$__afield = [];
$__aplace = [];
$__aexec = [];
foreach ($this->_afield as $col) {
$__afield[] = '`'.$col['field'].'`';
if ($col['numbe'] === true) {
$__aplace[] = $col['value'];
} else {
$__aplace[] = '?';
$__aexec[] = $col['value'];
}
}
$tsql .= substr($tfield,1);
$tsql .= ") VALUES (";
$tsql .= substr($tvalue,1);
$tsql .= ")";
$this->__db->Query($tsql);
$tsql = 'INSERT INTO '.$this->_ttable.' ('. implode(',', $__afield) .') VALUES ('. implode(',', $__aplace) .')';
$this->db->runQuery($tsql, $__aexec);
}
public function UpdateDB() {
$tsql = "UPDATE ".$this->__ttable." SET ";
$tfield = "";
for ($i=0; $i<count($this->__afield); $i++) {
$tfield .= ",".$this->__afield[$i]."=".(($this->__anomor[$i])?"":"'").$this->__avalue[$i].(($this->__anomor[$i])?"":"'");
public function UpdateDB(): void {
$__aplace = [];
$__awhere = [];
$__aexec = [];
foreach ($this->_afield as $col) {
if ($col['numbe'] === true) {
$__aplace[] = '`'.$col['field'].'`='. $col['value'];
} else {
$__aplace[] = '`'.$col['field'].'`=?';
$__aexec[] = $col['value'];
}
}
$tsql .= substr($tfield,1);
$tsql .= ($this->__twhere=="") ? "" : $this->__twhere;
$this->__db->Query($tsql);
foreach ($this->_awhere as $col) {
if ($col['numbe'] === true) {
$__awhere[] = '`'.$col['field'].'`='. $col['value'];
} else {
$__awhere[] = '`'.$col['field'].'`=?';
$__aexec[] = $col['value'];
}
}
$tsql = 'UPDATE '.$this->_ttable.' SET '. implode(',', $__aplace) .' WHERE '. implode(' AND ', $__awhere);
$this->db->runQuery($tsql, $__aexec);
}
public function DeleteDB() {
$tsql = "DELETE FROM ".$this->__ttable;
$tsql .= ($this->__twhere=="") ? "" : $this->__twhere;
$this->__db->Query($tsql);
public function DeleteDB(): void {
$__awhere = [];
$__aexec = [];
foreach ($this->_awhere as $col) {
if ($col['numbe'] === true) {
$__awhere[] = '`'.$col['field'].'`='. $col['value'];
} else {
$__awhere[] = '`'.$col['field'].'`=?';
$__aexec[] = $col['value'];
}
}
$tsql = 'DELETE FROM '.$this->_ttable.' WHERE '. implode(' AND ', $__awhere);
$this->db->runQuery($tsql, $__aexec);
}
public function LastInsertID() {
return $this->__db->LastInsertID();
public function LastInsertID(): int {
return $this->db->lastInsertId();
}
}