diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6ef218 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea + diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/Tests/Test.php b/Tests/Test.php old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 diff --git a/src/.idea/.name b/src/.idea/.name deleted file mode 100644 index e831038..0000000 --- a/src/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -src \ No newline at end of file diff --git a/src/.idea/encodings.xml b/src/.idea/encodings.xml deleted file mode 100644 index 97626ba..0000000 --- a/src/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/.idea/misc.xml b/src/.idea/misc.xml deleted file mode 100644 index 4a870d5..0000000 --- a/src/.idea/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/.idea/modules.xml b/src/.idea/modules.xml deleted file mode 100644 index f669a0e..0000000 --- a/src/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/.idea/src.iml b/src/.idea/src.iml deleted file mode 100644 index c956989..0000000 --- a/src/.idea/src.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/.idea/workspace.xml b/src/.idea/workspace.xml deleted file mode 100644 index a9947a3..0000000 --- a/src/.idea/workspace.xml +++ /dev/null @@ -1,339 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1476789396020 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Lib/Mongodb.php b/src/Lib/Mongodb.php new file mode 100755 index 0000000..1a08ebf --- /dev/null +++ b/src/Lib/Mongodb.php @@ -0,0 +1,578 @@ +_user; + $option['password'] = $this->_pass; + if ($this->_name !== null) { + $option['db'] = $this->_name; + } + + //$dsn = "mongodb://{$this->_host}:{$this->_port}"; + + $instance = new Mongodb_instance($config, $option); + + return $instance; + } + +} + +class Mongodb_instance implements DIDatabaseNoSql +{ + /** + * 连接对象实例 + * + * @access private + * @var object + */ + private $_instance = null; + + /** + * 数据库名称 + * + * @access private + * @var object + */ + private $_db = null; + + /** + * 集合名称 + * + * @access private + * @var object + */ + private $_collection = null; + + /** + * 是否在进行事务处理 + * + * @access private + * @staticvar + * @var boolean + */ + private static $_begin_action = false; + + /** + * 文档 + * @var array + */ + public $document = []; + + /** + * 构造器 + * Mongodb_instance constructor. + * @param $dns + * @param array $options + */ + public function __construct($dns, $options = []) + { + //'mongodb://work:work@121.199.53.9:27017/narada' + $this->_db = $options['db']; + $this->_instance = new \MongoDB\Driver\Manager($dns, $options); + } + + /** + * 设置集合 + * @param $collection + * @return + */ + public function setCollection($collection) + { + if ($collection) { + $this->_collection = $collection; + + } + + return $this; + } + + /** + * 选择集合 + * @return + */ + public function selectCollection() + { + return $this->_db . '.' . $this->_collection; + } + + /** + * 选择集合 + * @return + */ + public function collection() + { + return $this->_collection; + } + + /** + * mongodb 执行命令 + * + * @param string $sql + * @return object + */ + private function _query($sql,$options = []) + { + + return new Query($sql, $options); + } + + /** + * @param $sql + * @return + */ + private function _command($sql,$options = []) + { + return new Command($sql,$options); + } + + + + /** + * 开启事务 + * @return \MongoDB\\Session + * @throws + */ + public function getSession() + { + try { + + $session = $this->_instance->startSession(); + + $session->startTransaction([ + 'readConcern' => new \MongoDB\Driver\ReadConcern("snapshot"), + 'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDb\Driver\WriteConcern::MAJORITY) + ]); + + return $session; + + } catch (\MongoDB\Driver\Exception\Exception $e) { + printf("Other error: %s\n", $e->getMessage()); + exit; + } + } + + /** + * 事务操作语句 + * @param $data + * @param $type + * @return mixed + * @throws + */ + protected function myExecuteBulkWrite($data,$type,$session) + { + try { + $bulk = new BulkWrite; + + /*类型*/ + if (empty($type)) { + printf("Other error: %s\n", "不支持的批处理操作类型 '{$type}'"); + exit; + } + + $insertedIds = null; + + foreach ($data as $k => $item) { + switch ($type) { + case 'insert': + /*插入*/ + $insertedIds[$k] = $bulk->insert($item); + break; + case 'update': + /*更新*/ + $bulk->update($item['condition'], $item['document'], $item['options']); + break; + case 'delete': + /*删除*/ + $bulk->delete($item['condition'], isset($item['options']) ? $item['options'] : []); + break; + default: + printf("Other error: %s\n", "不支持的批处理操作类型 '{$type}'"); + exit; + break; + } + } + + /*表名*/ + $names = $this->selectCollection(); + + + /*会话*/ + $options = $session ? ['session' => $session] : []; + + /*执行语句*/ + $writeResult = $this->_instance->executeBulkWrite($names, $bulk , $options); + /*ID*/ + $ret['insertedIds'] = $insertedIds; + + if ($type == 'insert') { + /*插入*/ + $ret['result'] = $writeResult->getInsertedCount(); + } else if($type == 'update') { + /*更新*/ + $ret['result'] = $writeResult->getModifiedCount(); + } else if ($type == 'delete') { + /*删除*/ + $ret['result'] = $writeResult->getDeletedCount(); + } + + return $ret; + + } catch (\MongoDB\Driver\Exception\Exception $e) { + printf("Other error: %s\n", $e->getMessage()); + exit; + } + } + + /** + * mongodb 执行命令 + * + * @param object $bulk + * @return object + */ + private function _executeBulkWrite($bulk) + { + try { + $writeConcern = new WriteConcern(WriteConcern::MAJORITY, 1000); + $result = $this->_instance->executeBulkWrite($this->selectCollection(), $bulk, $writeConcern); + } catch (BulkWriteException $e) { + $result = $e->getWriteResult(); + + // Check if the write concern could not be fulfilled + if ($writeConcernError = $result->getWriteConcernError()) { + printf("%s (%d): %s\n", + $writeConcernError->getMessage(), + $writeConcernError->getCode(), + var_export($writeConcernError->getInfo(), true) + ); + exit; + } + + // Check if any write operations did not complete at all + foreach ($result->getWriteErrors() as $writeError) { + printf("Operation#%d: %s (%d)\n", + $writeError->getIndex(), + $writeError->getMessage(), + $writeError->getCode() + ); + exit; + } + } catch (\MongoDB\Driver\Exception\Exception $e) { + printf("Other error: %s\n", $e->getMessage()); + exit; + } + + return $result; + } + + /** + * 返回所有数据 + * + * @access public + * @param string $sql + * @return mixed + * @throws + */ + public function fetchAll($sql,$options = []) + { + $rows = $this->_instance->executeQuery($this->selectCollection(), $this->_query($sql,$options)) + ->toArray(); + + return $rows; + } + + /** + * 返回单行数据 + * + * @access public + * @param array $sql + * @return mixed + * @throws + */ + public function fetch($sql,$options = []) + { + $rows = $this->_instance->executeQuery($this->selectCollection(), $this->_query($sql,$options)) + ->toArray(); + return $rows; + } + + /** + * 返回第一行第一列数据,一般用在聚合函数中 + * + * @access public + * @param string $sql + * @return mixed + */ + public function fetchOne($sql,$options = []) + { + return $this->fetch($sql,$options); + } + + /** + * + * 执行一个SQL语句 + * @param string $sql + * @return array|int + * @throws + */ + public function query($sql) + { + $result = $this->_instance->executeCommand($this->_db, $this->_command($sql))->toArray(); + + return $result; + } + + + /** + * delete助手 + * + * @param array $filter + * @access public + * @return object + */ + public function delete($filter) + { + $bulk = new BulkWrite; + $bulk->delete($filter); + + return $this->_executeBulkWrite($bulk)->getDeletedCount(); + } + + /** + * 删除(物理删除,事务) + * @param array $where 条件 + * @throws + * @return + */ + public function deleteTransaction($where,$session= null) + { + + if (empty($where)) { + return false; + } + + /*多条件更新*/ + $options['multi'] = true; + + $data[] = [ + 'condition' => $where, + 'options' => $options + ]; + + $ret = $this->myExecuteBulkWrite($data,'delete',$session); + + return $ret; + + } + + /** + * 删除(逻辑删除,事务) + * @param string $where 条件 + * @param string $update 更新数据 + * @param string $session + * @throws + * @return + */ + public function delTransaction($where,$update,$session=null) + { + + /*多条件更新*/ + $options['multi'] = true; + + $data[] = [ + 'condition' => $where, + 'document' => $update, + 'options' => $options + ]; + + $ret = $this->myExecuteBulkWrite($data,'update',$session); + + return $ret; + + } + + /** + * insert助手 + * + * @param array $data + * @access public + * @return object + */ + public function insert($data) + { + $bulk = new BulkWrite; + $bulk->insert($data); + + return $this->_executeBulkWrite($bulk)->getInsertedCount(); + } + + /** + * 插入数据(事务) + * @param $data + * @return mixed + * @throws + */ + public function insertTransaction($data,$session = null) + { + unset($data['offset']); + unset($data['pageNum']); + unset($data['limit']); + unset($data['actKey']); + unset($data['actStatus']); + + $ret = $this->myExecuteBulkWrite($data,'insert',$session); + + return $ret['insertedIds']; + + } + + /** + * 批量插入(事务) + * @param array $data 数据 + * @return bool + * @throws + */ + public function batchInsertTransaction($data,$session = null) + { + /*无需验证字段*/ + $model = $this->myExecuteBulkWrite($data,'insert',$session); + + return $model ? $model : false; + } + + /** + * update助手 + * + * @param array $filter + * @param array $data + * @access public + * @return object + */ + public function update($filter, $data) + { + $bulk = new BulkWrite; + $bulk->update($filter, ['$set' => $data]); + + return $this->_executeBulkWrite($bulk)->getModifiedCount(); + } + + /** + * 更新文档数据(多条更新,事务) + * @param array $where 条件 + * @param array $update 更新内容 + * @return bool + * @throws + */ + public function modifyTransaction($where,$update,$session = null) + { + /*验证更新内容是否存在$set*/ + if (!isset($update['$set']) && !isset($update['$inc'])) { + printf("Other error: %s\n", '语法错误:$update 中缺少 $set 操作符'); + exit; + } + + /*条件*/ + $options = []; + + /*多条件更新*/ + $options['multi'] = true; + + $data[] = [ + 'condition' => $where, + 'document' => $update, + 'options' => $options + ]; + + $ret = $this->myExecuteBulkWrite($data,'update',$session); + + return $ret ? $ret : false; + } + + + /** + * 聚合查询 + * @param $pipelines + * @param array $options + * @return array + * @throws + */ + public function aggregate($pipelines, $options = []) + { + if (!is_array($pipelines)) { + return []; + } + + if (!isset($options['cursor']) && empty($options['cursor'])) { + $returnCursor = false; + $options['cursor'] = new \stdClass(); + } else { + $returnCursor = true; + } + + $document = array_merge( + [ + 'aggregate' => $this->collection(), + 'pipeline' => $pipelines, + 'allowDiskUse' => false, + ], + $options + ); + + $cursor = $this->_instance->executeCommand($this->_db, $this->_command($document)); + + if ($returnCursor) { + return $cursor; + } + + return $cursor->toArray(); + + } + + + /** + * 设置或读取当前数据取值模式 + * + * @access public + * @param string $mode + * @return string/void + */ + public function fetchMode($mode = null) + { + } + + /** + * 获取最近插入的一行记录的ID值 + * + * @access public + * @return integer + */ + public function lastInsertId($seq = null) + { + } +} diff --git a/src/Lib/mysql.php b/src/Lib/Mysql.php similarity index 100% rename from src/Lib/mysql.php rename to src/Lib/Mysql.php diff --git a/src/Lib/Pdo.php b/src/Lib/Pdo.php old mode 100644 new mode 100755 diff --git a/src/Lib/mongodb.php b/src/Lib/mongodb.php deleted file mode 100755 index 2851142..0000000 --- a/src/Lib/mongodb.php +++ /dev/null @@ -1,371 +0,0 @@ -_user; - $option['password'] = $this->_pass; - if ($this->_name !== null) { - $option['db'] = $this->_name; - } - - //$dsn = "mongodb://{$this->_host}:{$this->_port}"; - - $instance = new Mongodb_instance($config, $option); - - return $instance; - } - -} - -class Mongodb_instance implements DIDatabaseNoSql -{ - /** - * 连接对象实例 - * - * @access private - * @var object - */ - private $_instance = null; - - /** - * 数据库名称 - * - * @access private - * @var object - */ - private $_db = null; - - /** - * 集合名称 - * - * @access private - * @var object - */ - private $_collection = null; - - /** - * 是否在进行事务处理 - * - * @access private - * @staticvar - * @var boolean - */ - private static $_begin_action = false; - - /** - * 构造器 - * Mongodb_instance constructor. - * @param $dns - * @param array $options - */ - public function __construct($dns, $options = []) - { - //'mongodb://work:work@121.199.53.9:27017/narada' - $this->_db = $options['db']; - $this->_instance = new Manager($dns, $options); - } - - /** - * 设置集合 - * @param $collection - * @return \MongoCollection - */ - public function setCollection($collection) - { - if ($collection) { - $this->_collection = $collection; - - } - return $this; - } - - /** - * 选择集合 - * @param $collection - * @return \MongoCollection - */ - public function selectCollection() - { - return $this->_db . '.' . $this->_collection; - } - - /** - * 选择集合 - * @return \MongoCollection - */ - public function collection() - { - return $this->_collection; - } - - /** - * mongodb 执行命令 - * - * @param string $sql - * @return object - */ - private function _query($sql, $options = []) - { - return new Query($sql, $options); - } - - /** - * mongodb 执行命令 - * - * @param string $sql - * @return object - */ - private function _command($sql) - { - $cmd = new Command($sql); - $rows = $this->_instance->executeCommand($this->_db, $cmd)->toArray(); - - return $rows; - } - - /** - * mongodb 执行命令 - * - * @param object $bulk - * @return object - */ - private function _executeBulkWrite($bulk) - { - try { - $writeConcern = new WriteConcern(WriteConcern::MAJORITY, 1000); - $result = $this->_instance->executeBulkWrite($this->selectCollection(), $bulk, $writeConcern); - } catch (BulkWriteException $e) { - $result = $e->getWriteResult(); - - // Check if the write concern could not be fulfilled - if ($writeConcernError = $result->getWriteConcernError()) { - printf("%s (%d): %s\n", - $writeConcernError->getMessage(), - $writeConcernError->getCode(), - var_export($writeConcernError->getInfo(), true) - ); - exit; - } - - // Check if any write operations did not complete at all - foreach ($result->getWriteErrors() as $writeError) { - printf("Operation#%d: %s (%d)\n", - $writeError->getIndex(), - $writeError->getMessage(), - $writeError->getCode() - ); - exit; - } - } catch (\MongoDB\Driver\Exception\Exception $e) { - printf("Other error: %s\n", $e->getMessage()); - exit; - } - - return $result; - } - - /** - * 返回所有数据 - * - * @access public - * @param string $sql - * @return mixed - */ - public function fetchAll($sql, $options = []) - { - return $this->fetch($sql, $options); - } - - /** - * 返回单行数据 - * - * @access public - * @param array $sql - * @return mixed - */ - public function fetch($sql, $options = []) - { - $rows = $this->_instance->executeQuery($this->selectCollection(), $this->_query($sql, $options)) - ->toArray(); - - return $rows; - } - - /** - * 返回第一行第一列数据,一般用在聚合函数中 - * - * @access public - * @param string $sql - * @return mixed - */ - public function fetchOne($sql) - { - return $this->fetch($sql); - } - - /** - * 执行一个SQL语句 - * - * @access public - * @param string $sql - * @return int - */ - public function query($sql) - { - return $this->_command($sql); - } - - /** - * delete助手 - * - * @param array $filter - * @access public - * @return object - */ - public function count($filter) - { - $bulk = new BulkWrite; - $bulk->count($filter); - - return $this->_executeBulkWrite($bulk)->getDeletedCount(); - } - - /** - * delete助手 - * - * @param array $filter - * @access public - * @return object - */ - public function delete($filter) - { - $bulk = new BulkWrite; - $bulk->delete($filter); - - return $this->_executeBulkWrite($bulk)->getDeletedCount(); - } - - /** - * insert助手 - * - * @param array $data - * @access public - * @return object - */ - public function insert($data) - { - $bulk = new BulkWrite; - $bulk->insert($data); - - return $this->_executeBulkWrite($bulk)->getInsertedCount(); - } - - /** - * update助手 - * - * @param array $filter - * @param array $data - * @access public - * @return object - */ - public function update($filter, $data) - { - $bulk = new BulkWrite; - $bulk->update($filter, ['$set' => $data]); - - return $this->_executeBulkWrite($bulk)->getModifiedCount(); - } - - /** - * 聚合查询 - * @param $pipelines - * @param array $options - * @return array - */ - public function aggregate($pipelines, $options = []) - { - if (!is_array($pipelines)) { - return []; - } - - try { - - $document = array_merge( - [ - 'aggregate' => $this->collection(), - 'pipeline' => $pipelines, - 'allowDiskUse' => false, - ], $options - ); - - $cursor = $this->_command($document); - - if (empty($cursor)) { - return []; - } - - $rows = []; - - // 整理格式 - foreach ($cursor[0]->result as $key => $item) { - $item = json_decode(json_encode($item, true), TRUE); - $item['_id'] = isset($item['_id']['$oid']) ? $item['_id']['$oid'] : $item['_id']; - $rows[$key] = $item; - } - - return $rows; - } catch (\Exception $e) { - printf("Other error: %s\n", $e->getMessage()); - exit; - } - - - } - - - /** - * 设置或读取当前数据取值模式 - * - * @access public - * @param string $mode - * @return string/void - */ - public function fetchMode($mode = null) - { - } - - /** - * 获取最近插入的一行记录的ID值 - * - * @access public - * @return integer - */ - public function lastInsertId($seq = null) - { - } -} diff --git a/src/NoSql.php b/src/NoSql.php index 063bb76..afd91dc 100755 --- a/src/NoSql.php +++ b/src/NoSql.php @@ -201,6 +201,12 @@ public function __get($engine) //数据库引擎接口 interface DIDatabaseNoSql { + /** + * 开启会话 + * @return mixed + */ + public function getSession(); + /** * 获取当行数据 * @@ -208,7 +214,16 @@ interface DIDatabaseNoSql * @param string $sql * @return array */ - public function fetch($sql); + public function fetchOne($sql,$options = []); + + /** + * 获取数据 + * + * @access public + * @param string $sql + * @return array + */ + public function fetch($sql,$options = []); /** * 执行一条SQL语句 @@ -235,6 +250,23 @@ public function fetchMode($mode = null); */ public function delete($filter); + /** + * 删除(物理删除,事务) + * @param $where + * @param null $session + * @return mixed + */ + public function deleteTransaction($where,$session= null); + + /** + * 删除(逻辑删除,事务) + * @param $where + * @param $update + * @param null $session + * @return mixed + */ + public function delTransaction($where,$update,$session=null); + /** * 插入操作助手 * @@ -244,6 +276,22 @@ public function delete($filter); */ public function insert($data); + /** + * 插入数据(事务) + * @param $data + * @param null $session + * @return mixed + */ + public function insertTransaction($data,$session = null); + + /** + * 批量插入(事务) + * @param $data + * @param null $session + * @return mixed + */ + public function batchInsertTransaction($data,$session = null); + /** * 更新操作助手 * @@ -254,6 +302,15 @@ public function insert($data); */ public function update($filter, $data); + /** + * 更新(事务) + * @param $where + * @param $update + * @param null $session + * @return mixed + */ + public function modifyTransaction($where,$update,$session = null); + /** * 聚合操作助手 * @param $pipelines diff --git a/src/Plugin/Select.php b/src/Plugin/Select.php index eed399d..1e7a283 100755 --- a/src/Plugin/Select.php +++ b/src/Plugin/Select.php @@ -306,14 +306,7 @@ private function _toString() foreach ($_from as $key => $val) { if (is_array($val) && 2 == count($val)) { $_other_name = ''; - //list($k, $v) = each($val[0]); - if (is_array($val[0])) { - $k = key($val[0]); - $v = current($val[0]); - } else { - $k = $v = $val[0]; - } - + list($k, $v) = each($val[0]); if (!is_integer($k)) { $_tmp_tabs .= $this->wrap($v) . ' ' . $this->_keys[self::FLAG_AS] . ' ' . $this->wrap( $k @@ -335,15 +328,10 @@ private function _toString() ); } } else { - if ($_other_name && strpos($v, trim($_other_name, '`') . '.') !== 0 && !preg_match( - '/\w+\(.*?\)/', $v - ) - ) { + if ($_other_name && strpos($v, trim($_other_name, '`').'.') !== 0 && !preg_match('/\w+\(.*?\)/', $v)) { $val[1][$k] = $_other_name . '.' . $this->wrap($v); - } elseif ($_other_name && strpos($v, trim($_other_name, '`') . '.') === 0) { - $val[1][$k] = $_other_name . '.' . $this->wrap( - str_replace((trim($_other_name, '`') . '.'), '', $v) - ); + } elseif ($_other_name && strpos($v, trim($_other_name, '`').'.') === 0) { + $val[1][$k] = $_other_name . '.' . $this->wrap(str_replace( (trim($_other_name, '`').'.'),'', $v)); } } } @@ -367,13 +355,7 @@ private function _toString() $_tmp_tabs = ''; $_tmp_cols = ''; $_other_name = ''; - //list($k, $v) = each($_tables); - if (is_array($_tables)) { - $k = key($_tables); - $v = current($_tables); - } else { - $k = $v = $_tables; - } + list($k, $v) = each($_tables); if (!is_integer($k)) { $_tmp_tabs .= $this->wrap($v) . ' ' . $this->_keys[self::FLAG_AS] . ' ' . $this->wrap( $k @@ -390,9 +372,7 @@ private function _toString() $_other_name && $_columns[$k] = $_other_name . '.' . $this->wrap($v); } if (!is_integer($k)) { - $_columns[$k] = $this->wrap( - $_columns[$k] - ) . ' ' . $this->_keys[self::FLAG_AS] . ' ' . $this->wrap($k); + $_columns[$k] = $this->wrap($_columns[$k]) . ' ' . $this->_keys[self::FLAG_AS] . ' ' . $this->wrap($k); } } $_tmp_cols = implode(', ', $_columns) . ', '; @@ -457,7 +437,7 @@ private function _toString() } $_lock_string = ''; - if (array_key_exists(self::FLAG_LOCK, $this->_parts) && $this->_parts[self::FLAG_LOCK]) { + if ( array_key_exists(self::FLAG_LOCK, $this->_parts) && $this->_parts[self::FLAG_LOCK]) { $_lock_string = ' ' . $this->_keys[self::FLAG_LOCK]; } @@ -465,7 +445,7 @@ private function _toString() $_from_string = $_from_string ? ' ' . $this->_keys[self::FLAG_FROM] . ' ' . trim($_from_string, ', ') : ''; $_join_string = $_join_string ? ' ' . trim($_join_string) : ''; - $_where_string = $_where_string ? ' ' . $this->_keys[self::FLAG_WHERE] . ' ' . rtrim( + $_where_string = $_where_string ? ' ' . $this->_keys[self::FLAG_WHERE] . ' ' . rtrim( $_where_string, $this->_keys[self::FLAG_AND] . $this->_keys[self::FLAG_OR] . ' ' ) : ''; diff --git a/src/SqlTranslator.php b/src/SqlTranslator.php index 90a1748..3e273e5 100755 --- a/src/SqlTranslator.php +++ b/src/SqlTranslator.php @@ -135,11 +135,11 @@ protected function wrap($columns) if ($columns == '*' || strpos($columns, '`') === 0) { return $columns; } - preg_match('/(^#)(.+)/s', $columns, $match); if (array_key_exists(1, $match) && $match[1]) { return $match[2]; } + return '`' . $columns . '`'; }