rewrite mysql unsupported function
This commit is contained in:
+2
-12
@@ -6,9 +6,9 @@
|
||||
Desc. : Class database MySQL / MariaDB
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 2nd, 2007.
|
||||
Last Modified : October 19th, 2023.
|
||||
Last Modified : August 27th, 2026.
|
||||
|
||||
(c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM.
|
||||
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
@@ -108,16 +108,6 @@ final class MySQL {
|
||||
return $this->rs;
|
||||
}
|
||||
|
||||
function Execute($sqry = "", $aval = []) {//oke
|
||||
if ($sqry == "" || count($aval) == 0) return 0;
|
||||
if (!$this->Connect()) return 0;
|
||||
if ($this->rs) $this->Free();
|
||||
$this->rs = $this->conn->execute_query($sqry, $aval);
|
||||
$this->row = 0;
|
||||
if (!$this->rs) $this->ErrHandler("Invalid SQL: " . $this->conn->error);
|
||||
return $this->rs;
|
||||
}
|
||||
|
||||
function Next() {//oke
|
||||
if (!$this->rs) {
|
||||
$this->ErrHandler("Cannot move cursor to next record!");
|
||||
|
||||
+34
-32
@@ -6,9 +6,9 @@
|
||||
Desc. : Class Query database
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : February 2nd, 2007.
|
||||
Last Modified : December 17th, 2023.
|
||||
Last Modified : August 27th, 2026.
|
||||
|
||||
(c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM.
|
||||
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
@@ -79,81 +79,83 @@ final class SQL {
|
||||
|
||||
public function InsertDB() {//oke
|
||||
$_columns = implode(', ', array_keys($this->__avalue));
|
||||
$_aholder = []; $_avalues = [];
|
||||
$_avalue = [];
|
||||
foreach ($this->__avalue as $aval) {
|
||||
if ($aval['num'] == true) {
|
||||
$_aholder[] = $aval['value'];
|
||||
if ($aval['num'] === true) {
|
||||
$_avalue[] = $aval['value'];
|
||||
} else {
|
||||
$_aholder[] = "?";
|
||||
$_avalues[] = $aval['value'] ?? "";
|
||||
$_avalue[] = "'" . $aval['value'] . "'";
|
||||
}
|
||||
}
|
||||
$_holder = implode(', ', $_aholder);
|
||||
$_tsql = "INSERT INTO {$this->__ttable} ({$_columns}) VALUES ({$_holder})";
|
||||
$this->__db->Execute($_tsql, $_avalues);
|
||||
$_value = implode(', ', $_avalue);
|
||||
$_tsql = "INSERT INTO {$this->__ttable} ({$_columns}) VALUES ({$_value})";
|
||||
$this->__db->Query($_tsql);
|
||||
}
|
||||
|
||||
public function UpdateDB() {//oke
|
||||
$_aupdate = []; $_awhere = []; $_avalues = [];
|
||||
$_aupdate = []; $_awhere = [];
|
||||
foreach ($this->__avalue as $field => $aval) {
|
||||
if ($aval['num'] == true) {
|
||||
$_aupdate[] = "`{$field}` = " . $aval['value'];
|
||||
} else {
|
||||
$_aupdate[] = "`{$field}` = ?";
|
||||
$_avalues[] = $aval['value'] ?? "";
|
||||
$_aupdate[] = "`{$field}` = '" . $aval['value'] . "'";
|
||||
}
|
||||
}
|
||||
foreach ($this->__awhere as $field => $val) {
|
||||
$_awhere[] = "`{$field}` = ?";
|
||||
$_avalues[] = $val ?? "";
|
||||
$_awhere[] = "`{$field}` = '" . $val . "'";
|
||||
}
|
||||
$_update = implode(", ", $_aupdate);
|
||||
$_where = implode(" AND ", $_awhere);
|
||||
$_tsql = "UPDATE {$this->__ttable} SET {$_update} WHERE {$_where}";
|
||||
$this->__db->Execute($_tsql, $_avalues);
|
||||
$this->__db->Query($_tsql);
|
||||
}
|
||||
|
||||
public function DeleteDB() {//oke
|
||||
$_awhere = []; $_avalues = [];
|
||||
$_awhere = [];
|
||||
foreach ($this->__awhere as $field => $val) {
|
||||
$_awhere[] = "`{$field}` = ?";
|
||||
$_avalues[] = $val ?? "";
|
||||
$_awhere[] = "`{$field}` = '" . $val . "'";
|
||||
}
|
||||
$_where = implode(" AND ", $_awhere);
|
||||
$_tsql = "DELETE FROM {$this->__ttable} WHERE {$_where}";
|
||||
$this->__db->Execute($_tsql, $_avalues);
|
||||
$this->__db->Query($_tsql);
|
||||
}
|
||||
|
||||
public function fastInsertDB($nama_tabel = "", $adata = []) {//oke
|
||||
if ($nama_tabel=="" || count($adata)==0) return false;
|
||||
$_columns = implode(', ', array_keys($adata));
|
||||
$_holder = implode(', ', array_fill(0, count($adata), "?"));
|
||||
$_avalues = array_map(fn($val) => $val ?? "", array_values($adata));
|
||||
$_tsql = "INSERT IGNORE INTO {$nama_tabel} ({$_columns}) VALUES ({$_holder})";
|
||||
$this->__db->Execute($_tsql, $_avalues);
|
||||
$_values = "'". implode("', '", array_values($adata)) ."'";
|
||||
$_tsql = "INSERT IGNORE INTO {$nama_tabel} ({$_columns}) VALUES ({$_values})";
|
||||
$this->__db->Query($_tsql);
|
||||
return true;
|
||||
}
|
||||
|
||||
function fastUpdateDB($nama_tabel = "", $adata = [], $awhere = []) {//oke
|
||||
if ($nama_tabel=="" || count($adata)==0 || count($awhere)==0) return false;
|
||||
$_aupdate = array_map(fn($key) => "`{$key}` = ?", array_keys($adata));
|
||||
$_awhere = array_map(fn($key) => "`{$key}` = ?", array_keys($awhere));
|
||||
$_avalues = array_merge(array_values($adata), array_values($awhere));
|
||||
$_avalues = array_map(fn($val) => $val ?? "", $_avalues);
|
||||
$_aupdate = [];
|
||||
foreach ($adata as $field => $val) {
|
||||
if (in_array($field, $awhere)) continue;
|
||||
$_aupdate[] = "`{$field}` = '" . $val . "'";
|
||||
}
|
||||
$_awhere = [];
|
||||
foreach ($awhere as $field => $val) {
|
||||
$_awhere[] = "`{$field}` = '" . $val . "'";
|
||||
}
|
||||
$_update = implode(", ", $_aupdate);
|
||||
$_where = implode(" AND ", $_awhere);
|
||||
$_tsql = "UPDATE {$nama_tabel} SET {$_update} WHERE {$_where}";
|
||||
$this->__db->Execute($_tsql, $_avalues);
|
||||
$this->__db->Query($_tsql);
|
||||
return true;
|
||||
}
|
||||
|
||||
function fastDeleteDB($nama_tabel = "", $awhere = []) {//oke
|
||||
if ($nama_tabel=="" || count($awhere)==0) return false;
|
||||
$_awhere = array_map(fn($key) => "`{$key}` = ?", array_keys($awhere));
|
||||
$_avalues = array_map(fn($val) => $val ?? "", array_values($awhere));
|
||||
$_awhere = [];
|
||||
foreach ($awhere as $field => $val) {
|
||||
$_awhere[] = "`{$field}` = '" . $val . "'";
|
||||
}
|
||||
$_where = implode(" AND ", $_awhere);
|
||||
$_tsql = "DELETE FROM {$nama_tabel} WHERE {$_where}";
|
||||
$this->__db->Execute($_tsql, $_avalues);
|
||||
$this->__db->Query($_tsql);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user