-
Notifications
You must be signed in to change notification settings - Fork 38
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Problem
Builder
and Connection
methods that return raw sql (toRawSql()
, getRawQueryLog()
, etc.) throw an error when connection is read-only. For example, with this configuration:
[
'driver' => 'pgsql',
'read' => [
'host' => '...',
'port' => '...',
],
'write' => [/* empty */],
// Other parameters, they don't have `host`, `port` or `url`.
]
I have this exception (code from tinker):
> DB::query()->from('users')->where('username', 'name')->toRawSql()
PDOException SQLSTATE[08006] [7] connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Reason
After some digging, I've found that enhanced connection uses getPdo()
in order to escape strings:
return $this->getPdo()->quote($value); |
While Laravel's connection uses getReadPdo()
:
https://github.com/laravel/framework/blob/0b52acbdef545689017b6852c2b44918daeae9d3/src/Illuminate/Database/Connection.php#L1138
After changing that line in vendor, raw sql methods seem to be fixed, but I haven't done extended testing for other functionality, and I also don't know whether this is intentional or not, so I'm not sure if this change is enough to submit a PR.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working