rewrite mysql unsupported function

This commit is contained in:
2026-08-27 10:33:24 +07:00
parent 9c469b76d5
commit 97ff6e2ed0
2 changed files with 36 additions and 44 deletions
+2 -12
View File
@@ -6,9 +6,9 @@
Desc. : Class database MySQL / MariaDB Desc. : Class database MySQL / MariaDB
Created By : Siau Pheng ([email protected]). Created By : Siau Pheng ([email protected]).
Created Date : February 2nd, 2007. 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; 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 function Next() {//oke
if (!$this->rs) { if (!$this->rs) {
$this->ErrHandler("Cannot move cursor to next record!"); $this->ErrHandler("Cannot move cursor to next record!");
+34 -32
View File
@@ -6,9 +6,9 @@
Desc. : Class Query database Desc. : Class Query database
Created By : Siau Pheng ([email protected]). Created By : Siau Pheng ([email protected]).
Created Date : February 2nd, 2007. 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 public function InsertDB() {//oke
$_columns = implode(', ', array_keys($this->__avalue)); $_columns = implode(', ', array_keys($this->__avalue));
$_aholder = []; $_avalues = []; $_avalue = [];
foreach ($this->__avalue as $aval) { foreach ($this->__avalue as $aval) {
if ($aval['num'] == true) { if ($aval['num'] === true) {
$_aholder[] = $aval['value']; $_avalue[] = $aval['value'];
} else { } else {
$_aholder[] = "?"; $_avalue[] = "'" . $aval['value'] . "'";
$_avalues[] = $aval['value'] ?? "";
} }
} }
$_holder = implode(', ', $_aholder); $_value = implode(', ', $_avalue);
$_tsql = "INSERT INTO {$this->__ttable} ({$_columns}) VALUES ({$_holder})"; $_tsql = "INSERT INTO {$this->__ttable} ({$_columns}) VALUES ({$_value})";
$this->__db->Execute($_tsql, $_avalues); $this->__db->Query($_tsql);
} }
public function UpdateDB() {//oke public function UpdateDB() {//oke
$_aupdate = []; $_awhere = []; $_avalues = []; $_aupdate = []; $_awhere = [];
foreach ($this->__avalue as $field => $aval) { foreach ($this->__avalue as $field => $aval) {
if ($aval['num'] == true) { if ($aval['num'] == true) {
$_aupdate[] = "`{$field}` = " . $aval['value']; $_aupdate[] = "`{$field}` = " . $aval['value'];
} else { } else {
$_aupdate[] = "`{$field}` = ?"; $_aupdate[] = "`{$field}` = '" . $aval['value'] . "'";
$_avalues[] = $aval['value'] ?? "";
} }
} }
foreach ($this->__awhere as $field => $val) { foreach ($this->__awhere as $field => $val) {
$_awhere[] = "`{$field}` = ?"; $_awhere[] = "`{$field}` = '" . $val . "'";
$_avalues[] = $val ?? "";
} }
$_update = implode(", ", $_aupdate); $_update = implode(", ", $_aupdate);
$_where = implode(" AND ", $_awhere); $_where = implode(" AND ", $_awhere);
$_tsql = "UPDATE {$this->__ttable} SET {$_update} WHERE {$_where}"; $_tsql = "UPDATE {$this->__ttable} SET {$_update} WHERE {$_where}";
$this->__db->Execute($_tsql, $_avalues); $this->__db->Query($_tsql);
} }
public function DeleteDB() {//oke public function DeleteDB() {//oke
$_awhere = []; $_avalues = []; $_awhere = [];
foreach ($this->__awhere as $field => $val) { foreach ($this->__awhere as $field => $val) {
$_awhere[] = "`{$field}` = ?"; $_awhere[] = "`{$field}` = '" . $val . "'";
$_avalues[] = $val ?? "";
} }
$_where = implode(" AND ", $_awhere); $_where = implode(" AND ", $_awhere);
$_tsql = "DELETE FROM {$this->__ttable} WHERE {$_where}"; $_tsql = "DELETE FROM {$this->__ttable} WHERE {$_where}";
$this->__db->Execute($_tsql, $_avalues); $this->__db->Query($_tsql);
} }
public function fastInsertDB($nama_tabel = "", $adata = []) {//oke public function fastInsertDB($nama_tabel = "", $adata = []) {//oke
if ($nama_tabel=="" || count($adata)==0) return false; if ($nama_tabel=="" || count($adata)==0) return false;
$_columns = implode(', ', array_keys($adata)); $_columns = implode(', ', array_keys($adata));
$_holder = implode(', ', array_fill(0, count($adata), "?")); $_values = "'". implode("', '", array_values($adata)) ."'";
$_avalues = array_map(fn($val) => $val ?? "", array_values($adata)); $_tsql = "INSERT IGNORE INTO {$nama_tabel} ({$_columns}) VALUES ({$_values})";
$_tsql = "INSERT IGNORE INTO {$nama_tabel} ({$_columns}) VALUES ({$_holder})"; $this->__db->Query($_tsql);
$this->__db->Execute($_tsql, $_avalues);
return true; return true;
} }
function fastUpdateDB($nama_tabel = "", $adata = [], $awhere = []) {//oke function fastUpdateDB($nama_tabel = "", $adata = [], $awhere = []) {//oke
if ($nama_tabel=="" || count($adata)==0 || count($awhere)==0) return false; if ($nama_tabel=="" || count($adata)==0 || count($awhere)==0) return false;
$_aupdate = array_map(fn($key) => "`{$key}` = ?", array_keys($adata)); $_aupdate = [];
$_awhere = array_map(fn($key) => "`{$key}` = ?", array_keys($awhere)); foreach ($adata as $field => $val) {
$_avalues = array_merge(array_values($adata), array_values($awhere)); if (in_array($field, $awhere)) continue;
$_avalues = array_map(fn($val) => $val ?? "", $_avalues); $_aupdate[] = "`{$field}` = '" . $val . "'";
}
$_awhere = [];
foreach ($awhere as $field => $val) {
$_awhere[] = "`{$field}` = '" . $val . "'";
}
$_update = implode(", ", $_aupdate); $_update = implode(", ", $_aupdate);
$_where = implode(" AND ", $_awhere); $_where = implode(" AND ", $_awhere);
$_tsql = "UPDATE {$nama_tabel} SET {$_update} WHERE {$_where}"; $_tsql = "UPDATE {$nama_tabel} SET {$_update} WHERE {$_where}";
$this->__db->Execute($_tsql, $_avalues); $this->__db->Query($_tsql);
return true; return true;
} }
function fastDeleteDB($nama_tabel = "", $awhere = []) {//oke function fastDeleteDB($nama_tabel = "", $awhere = []) {//oke
if ($nama_tabel=="" || count($awhere)==0) return false; if ($nama_tabel=="" || count($awhere)==0) return false;
$_awhere = array_map(fn($key) => "`{$key}` = ?", array_keys($awhere)); $_awhere = [];
$_avalues = array_map(fn($val) => $val ?? "", array_values($awhere)); foreach ($awhere as $field => $val) {
$_awhere[] = "`{$field}` = '" . $val . "'";
}
$_where = implode(" AND ", $_awhere); $_where = implode(" AND ", $_awhere);
$_tsql = "DELETE FROM {$nama_tabel} WHERE {$_where}"; $_tsql = "DELETE FROM {$nama_tabel} WHERE {$_where}";
$this->__db->Execute($_tsql, $_avalues); $this->__db->Query($_tsql);
return true; return true;
} }