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

PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known. #30

Closed
linxlad opened this issue Jun 1, 2017 · 8 comments

Comments

@linxlad
Copy link

linxlad commented Jun 1, 2017

Hi there,

Firstly nice work.

Secondly I can't seem to be able to seed my db as the following error occurs...
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known.

I am running on Docker so my host is my service container name db.
My application has had no trouble connecting to the database and inserting entries, it's all configured in config.php.

Trace image

Config file
Registering DB Service
Registering Yarak Service
Yarak file

Connecting manually seems to work?

try {
    $pdo = new \PDO('mysql:host=dev_db;dbname=realworlddb;port=3306;charset=utf8', 'root', 'secret');
    $stmt = $pdo->query('SELECT * FROM users');
    $result = $stmt->fetchAll();
    var_dump($result); exit;
} catch (\Exception $e) {
    var_dump($e); exit;
}

UPDATE:

It fails at this line...
https://github.com/zachleigh/yarak/blob/master/src/DB/Factories/ModelFactoryBuilder.php#L148
Though I can run the same type of code in a controller so maybe it's a CLI issue?

Do you know how I can debug this problem?

Thanks

@zachleigh
Copy link
Owner

Hi there. It seems to be set up fine. Were you able to run migrations or use anything else that required the db? Is it only failing with seeders?

@linxlad
Copy link
Author

linxlad commented Jun 1, 2017

Thanks for the reply Zach, I haven't tried a migration yet.

In my application controllers/models running new ModelClass(['my' => 'modelData']) is fine but on this line it won't work:
https://github.com/zachleigh/yarak/blob/master/src/DB/Factories/ModelFactoryBuilder.php#L148

I can try the other DB reliant stuff.

@linxlad
Copy link
Author

linxlad commented Jun 1, 2017

@zachleigh Yeah migrate also throws the same error.

Could it be the way it's bootstrapped in the Yarak file?

@zachleigh
Copy link
Owner

I just cloned your repo and played around with it. I was able to get migrations and seeds running using the setup you have so my guess is that Docker is to blame.

What happens if you call Yarak in your code, maybe in a controller:

use Yarak\Yarak;

Yarak::call('db:seed');

@linxlad
Copy link
Author

linxlad commented Jun 1, 2017

Yeah I'm wondering if it is Docker or something about my development environment.

Yarah::call('db:seed')

works like a charm.

Thanks for taking the time trying it out on my repo. We can rule out Yarak for now.

Thanks again :)

@zachleigh
Copy link
Owner

zachleigh commented Jun 3, 2017

Some things that could help you debug:
In the Yarak file, dump out the app config before the call to kernel::handle():

var_dump($di->get('config'));
die();

$kernel->handle();

Make sure your db config info is there.

In /src/DB/ConnectionResolver, comment out line 28. That line isnt necessary any more, but could be messing up your db connection.

In that same file, above line 28, create a PDO class and see if it creates it successfully and uses the correct credentials:

var_dump(new $dbClass($dbConfig));
die();

Calling yarak::migrate should trigger this.

Also, what OS are you using? Have you ever had trouble connecting to the DB from the command line before? Might try creating a simple php file that just connects to the db and then calling it from the command line. Also, check your cli php.ini file.

@linxlad
Copy link
Author

linxlad commented Jun 3, 2017

These are all good suggestions, thanks for debugging tips. Will try them out and report back.

@micheleangioni
Copy link
Contributor

@zachleigh it seems to be a Docker related problem, I think you can close this issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants