Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with arrays and integers #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Query/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ public function getDateTimeFormat()
*/
public function quote($value)
{
if (is_string($value))
return "'" . $value . "'";

if (is_array($value))
return "'" . implode("','", $value) . "'";
if (is_string($value)) {
return "'" . addslashes($value) . "'";
}

if (is_array($value)) {
return json_encode($value);
}
if (null === $value)
return '';

Expand Down
13 changes: 10 additions & 3 deletions src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct()
{
$this->grammar = new Grammar();
}

/**
* @param TransportInterface $transport
* @param string $sql
Expand Down Expand Up @@ -102,8 +102,15 @@ protected function prepareQueryBindings()
if (is_string($value))
$values[$key] = "'" . $value . "'";

if (is_array($value))
$values[$key] = "'" . implode("','", $value) . "'";
if (is_array($value)) {
$values[$key] = [];
foreach ($value as $v) {
$values[$key][] = is_numeric($v) ? $v : "'{$v}'";
}
$values[$key] = implode(',', $values[$key]);
}



if (null === $value)
$values[$key] = '';
Expand Down