".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
hello dear experts, good day,
i want to connect two pages on which a plugin like
- participants_database or
- wp-job-manager runs
i want to do that via wpdb to another database :: how to combine two wp-pages - here i want to discuss a approach that works - see https://wordpress.stackexchange.com/questions/1604/using-wpdb-to-connect-to-a-separate-database. There are serveral options - to do that.
- use Rest-API
- user other methods such als the following one which i want to discuss with you
If they are all on the same server under the same hosting account, that is helpful. In a case like that, you could write your custom code to access the other site’s database directly. This is discussed here, and it’s quite feasible: link: Using wpdb to connect to a separate database
see here the discussion of several approaches - which is so fruitful that i want to share it with you... - see https://wordpress.stackexchange.com/questions/1604/using-wpdb-to-connect-to-a-separate-database
[b]question[/b]: I want to connect wpdb to another database. How do I create the instance and pass it the database name/username/password?
Answer1: 134 votes Yes it's possible. The wpdb object can be used to access any database and query any table. Absolutely no need to be Wordpress related, which is very interesting. The benefit is the ability to use all the wpdb classes and functions like get_results, etc so that there's no need to re-invent the wheel. Here's how:
$mydb = new wpdb('username','password','database','localhost');
$rows = $mydb->get_results("select Name from my_table");
foreach ($rows as $obj) :
comment 1: you can also save time by using global $wpdb. But before firing ;[/CODE]$wpdb->get_results method,;[/CODE]
you must include wp-load.php as: [CODE]require_once('/your/wordpress/wp-load.php');[/CODE]
comment 2: Set WPDB prefix to make WP_Query and get_post to generate correct sql query by calling $mydb->set_prefix('wp_');
answer2: [ 30 votes ] Connecting to a second database is easy in WordPress, you simply create a new instance of the WPDB class and use it the same way you would use the standard $wpdb instance we all know and love.
Assuming the second database has the same login information as the main WP one you can even use the predefined constants
from wp-config.php to avoid hardcoding the login information.
* Instantiate the wpdb class to connect to your second database, $database_name
$second_db = new wpdb(DB_USER, DB_PASSWORD, $database_name, DB_HOST);
* Use the new database object just like you would use $wpdb
$results = $second_db->get_results($your_query);[/CODE]
comment 1: This is somewhat redundant to Wadih's answer but I think my code example is a bit clearer and its also important to remember the db login constant's as they are almost always the right ones to use and otherwise you risk issues when moving from dev->stage->live environments where the login details might change. – jerclarke Sep 11 '10 at 20:55
comment 2: Set WPDB prefix to make WP_Query and get_post to generate correct sql query by calling [CODE]$second_db->set_prefix('wp_'); [/CODE]
answer3: [ 21 votes ] no one has said this so I thought I'd add an even easier way..as long as your additional database has the same user/pass details to access it as your wordpress database you can use the database name before the table name like this
[CODE]$query = $wpdb->prepare('SELECT * FROM dbname.dbtable WHERE 1');
$result = $wpdb->get_results($query);[/CODE]
comment 1: From my experience, this only works to get data, i.e. using SELECT. You can't insert data.
comment 2: it will not work externally,
- see https://wordpress.stackexchange.com/questions/1604/using-wpdb-to-connect-to-a-separate-database
[b]Conclusio[/b]: well i like this approach very very much. The good thing - i am with the sites in question - i am on the same server - so i guess that this will work for me.
see the discussion of several approaches - which is so fruitful that i want to share it with you... - see https://wordpress.stackexchange.com/questions/1604/using-wpdb-to-connect-to-a-separate-database
any idea any experience !?
love to hear from you
To those who use Unity the 3D dev platform, I'm getting started with a project and want some version control to go with.
What are your experiences with version control? I've read that Unity supports Perforce and one other - also - proprietary VCS. Has anyone used Git or SVN with Unity? Any other methods I'm not aware of?
I need to install an Asp.Net Web API to IIS on a server as part of another app's installation. We're using Wix to create our installers. During installation of our app, we would also like to put our Web API in IIS on a server.
I see plenty of resources on how to deploy using VS, but how do I do this with an installation package?
How is this done?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
I'm working in VS2019 on a web project and once in a while this pops up when I go to simply run the code from within Visual Studios..... I know it has something to do with permissions at the URL but in this case I'm running to loacal server from within VS. How can my permissions change like that and what can I do to fix it? Thanks.
Hide Copy Code
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
Most likely causes:
A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
You probably have it set to run based on the selected document and your selected document is a folder or something that can't be browsed to. Right click a default page and choose to set it as default page.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
everything works but when I try to make it a partial view
If you are sure that you have called this script and it is a part of the DOM, and still this error comes, please share the browser console logs so that we can look into them. You can capture that using F12 and then visiting console (if some other tab is selected).
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
Can you show the content of your script.js file? The problem comes somewhere from there,
Somewhere at line 12, there is a call to the fileupload function and you can need to make sure that your fileupload script is loaded before line 12 (anywhere!).
One thing that is still bugging me is that why is jquery-3.1.0.min.js in this entire trace. Maybe you are causing a circular (or duplicate) script being loaded. Please verify that each script is loaded only one, and in a correct layout—like your normal view is working out, because this problem comes only in the partial view.