leomarquine / php-etl

Extract, Transform and Load data using PHP.
MIT License
180 stars 82 forks source link

PDOException: No handler for this scheme #14

Closed cklmercer closed 6 years ago

cklmercer commented 6 years ago

Background

Issue

After configuring my first pipeline I was greeted with the following error when attempting to execute it.

PDOException with message 'SQLSTATE[HY000] [2002] No handler for this scheme'

Details

The default database config for Laravel 5.7 sets the unix_socket option to an empty string. Whenever this package attempts to establish a connection it only checks to see if a socket option `isset. It doesn't check to see if the provided option is truthy.

This results in it generating adns option that looks something like the following: mysql:unix_socket=;dbname=default. I'm not sure if that's ever considered a valid option, however it certainly sent me down the rabbit hole.

Solution

The simplest solution, for me, was to completely remove the unix_socket option from my database configuration. Doing so resulted in a dns option that looks more like the following: mysql:host=127.0.0.1;port=3306;dbname=default which worked great for me.

I'm not sure if this is documented somewhere. I might have missed an aside or skimmed over something I should have read thoroughly, however, I wanted to share my findings just in case anybody else runs into this issue.

Code References

The following is the code that checks to see if a unix_socket option has been provided. The same method also checks for other settings, such as a host, port, etc. As you can see, it only checks to see if the option isset, and it does not check to ensure a non-empty string is provided. (Again, I'm not sure if an empty string is ever acceptable. If it isn't, it would be great to see this check extended to also check for truthiness.)

https://github.com/leomarquine/php-etl/blob/master/src/Database/Connectors/MySqlConnector.php#L36-L38

cklmercer commented 6 years ago

Looks like this is a duplicate of https://github.com/leomarquine/php-etl/issues/12