Files
zhamao-framework/src/ZM/DB/WhereBody.php

35 lines
953 B
PHP
Raw Normal View History

2020-03-02 16:14:20 +08:00
<?php
namespace ZM\DB;
trait WhereBody
{
protected $where_thing = [];
public function where($column, $operation_or_value, $value = null) {
2020-06-10 14:39:30 +08:00
if (!in_array($operation_or_value, ['=', '!=', '>', '<', '>=', '<=', 'IN', 'in'])) $this->where_thing['='][$column] = $operation_or_value;
2020-03-02 16:14:20 +08:00
elseif ($value !== null) $this->where_thing[$operation_or_value][$column] = $value;
else $this->where_thing['='][$column] = $operation_or_value;
return $this;
}
protected function getWhereSQL(){
$param = [];
$msg = '';
foreach($this->where_thing as $k => $v) {
foreach($v as $ks => $vs) {
if($param != []) {
$msg .= ' AND '.$ks ." $k ?";
} else {
$msg .= "$ks $k ?";
}
$param []=$vs;
}
}
2020-05-23 17:23:29 +08:00
if ($msg == '') $msg = 1;
2020-03-02 16:14:20 +08:00
return [$msg, $param];
}
2020-05-23 17:23:29 +08:00
}