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

39 lines
1.1 KiB
PHP
Raw Normal View History

<?php /** @noinspection PhpMissingReturnTypeInspection */
2020-03-02 16:14:20 +08:00
namespace ZM\DB;
2021-07-09 01:38:30 +08:00
/**
* Trait WhereBody
* @package ZM\DB
* @deprecated This will delete in 2.6 or future version, use \ZM\MySQL\MySQLManager::getConnection() instead
*/
2020-03-02 16:14:20 +08:00
trait WhereBody
{
protected $where_thing = [];
public function where($column, $operation_or_value, $value = null) {
2020-07-10 21:11:00 +08:00
if ($value !== null) $this->where_thing[$operation_or_value][$column] = $value;
elseif (!in_array($operation_or_value, ['=', '!=', '>', '<', '>=', '<=', 'IN', 'in'])) $this->where_thing['='][$column] = $operation_or_value;
2020-03-02 16:14:20 +08:00
else $this->where_thing['='][$column] = $operation_or_value;
return $this;
}
2021-02-09 17:09:09 +08:00
protected function getWhereSQL() {
2020-03-02 16:14:20 +08:00
$param = [];
$msg = '';
2021-02-09 17:09:09 +08:00
foreach ($this->where_thing as $k => $v) {
foreach ($v as $ks => $vs) {
if ($param != []) {
$msg .= ' AND ' . $ks . " $k ?";
2020-03-02 16:14:20 +08:00
} else {
$msg .= "$ks $k ?";
}
2021-02-09 17:09:09 +08:00
$param [] = $vs;
2020-03-02 16:14:20 +08:00
}
}
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
}