Skip to content

Commit

Permalink
1. RESA is now working recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
optiwariindia committed Jan 18, 2021
1 parent 93c71c1 commit dd79d35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "optiwariindia/database",
"description": "A library to connect database and use basic activities in database like create,select,insert,update,delete and drop using predefined methods",
"type": "library",
"version":"1.2.0",
"license": "MIT",
"authors": [
{
Expand Down
36 changes: 25 additions & 11 deletions src/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,16 @@ public function insert($table, $data)
$sql = "insert into $table set ";
$fld = array();
foreach ($data as $key => $value) {
if(is_array($value))$value=json_encode($value);
if (is_array($value)) {
$value = json_encode($value);
}

if (($key == "pass") || ($key == "passwd")) {
$fld[] = " $key=md5('{$value}')";
} else {
if($value=="now()"){
$fld[]=" $key = $value ";
}else{
if ($value == "now()") {
$fld[] = " $key = $value ";
} else {

$fld[] = " $key='{$value}'";
}
Expand All @@ -150,10 +153,13 @@ public function update($table, $data, $where = "")
$sql = "update `{$table}` set ";
$fld = array();
foreach ($data as $key => $value) {
if($value=="now()"){
$fld[]=" $key = $value ";
}else{
if(is_array($value))$value=json_encode($value);
if ($value == "now()") {
$fld[] = " $key = $value ";
} else {
if (is_array($value)) {
$value = json_encode($value);
}

$fld[] = (is_numeric($value)) ? " $key={$value}" : " $key='{$value}'";
}
}
Expand All @@ -175,7 +181,12 @@ public function resa($var)
{
$data = array();
foreach ($var as $key => $value) {
$data[$key] = $this->res($value);
if (is_array($value)) {
$data[$key] = $this->resa($value);
} else {
$data[$key] = $this->res($value);
}

}
return $data;
}
Expand All @@ -202,8 +213,11 @@ public function query($sql, $debug = false)
if (strstr($sql, "insert")) {
$id = $this->con->insert_id;
$this->disconnect();
$resp=array("result" => $result, 'id' => $id);
if($this->debug)$res["query"]=$sql;
$resp = array("result" => $result, 'id' => $id);
if ($this->debug) {
$res["query"] = $sql;
}

return $resp;
} else {
$this->disconnect();
Expand Down

0 comments on commit dd79d35

Please sign in to comment.