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

Multiple database connections in a loop #58

Open
gitsharki opened this issue Jul 12, 2019 · 0 comments
Open

Multiple database connections in a loop #58

gitsharki opened this issue Jul 12, 2019 · 0 comments

Comments

@gitsharki
Copy link

Hello Tareq, thank you for this wonderful project, it's been a great help!

I have an issue however that I haven't been able to solve in almost a day which is very unusual for me. Basically what's going on is that I have to pull some statistical data from multiple wordpress sites. I've created a csv config file listing all databases I need to access and so on.
I'm looping over all these dbs creating new $wpdb object at the top of my loop like so:

$wpdb = new wpdb( $host['dbuser'], $host['dbpass'], $host['dbname'], $host['host'] );
$GLOBALS['wpdb'] = $wpdb;

I then use my eloquent models to access some data along these lines:

$options = WPOptions::where('option_name','=','blah')->first();
$vehicles = Vehicles::all();

and so on. At the end of my loop I unset all database objects I created by using unset() and setting them to null to top it off.

Problem is the data I get back for each individual host and it's database is from the very first connection, so it looks like $wpdb stays static since first being created even though I unset() it and create a new one. I'm positive I'm using new db creds on each iteration so It's completely flabbergasting why this is happening.

All the databases are on separate hosts, and I watched tcpdump traffice to these hosts when I run my script, it's totally fine. I also setup query logging on these boxen, and I see my source host connecting but it's not running any queries these model requests should generate, so $wpdb object is created but it's not being used by /tareq1988/wp-eloquent/src/Eloquent/Database.php, only the first one is, not any of the new ones created at each loop iteration.

Please let me know if you have any ideas on how I can get this fixed.

Thank you so much!!!

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

1 participant