Skip to content

Commit

Permalink
Db::query() IN Supported (#102)
Browse files Browse the repository at this point in the history
* Db::query() `IN` Supported

When I use Db::query with param value type is  an array, like:
```
$sql = 'SELECT * FROM `table` WHERE `id`  IN (?) AND `type` = ?';
$param = [
    [1,2,3,4],
    1
];
Db::query($sql, $param);
// sql : SELECT * FROM `table` WHERE `id`  IN ('') AND `type` = '1'
```
so ~

* Update MysqlConnection.php

format
  • Loading branch information
Marico authored and huangzhhui committed Jun 22, 2018
1 parent 860167f commit 2f2049a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/db/src/Driver/Mysql/MysqlConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ private function formatSqlByParams(array $params = null)
foreach ($params as $key => $value) {
if ($value === null) {
$value = " null ";
} elseif (\is_array($value)) {
$value = "'" . \implode("','", \array_map('addslashes', $value)) . "'";
} else {
$value = "'" . addslashes($value) . "'";
$value = "'" . \addslashes($value) . "'";
}

if (\is_int($key)) {
Expand Down Expand Up @@ -273,4 +275,4 @@ private function transferQuestionMark()
}
$this->sql = $sql;
}
}
}

0 comments on commit 2f2049a

Please sign in to comment.