Access Other MySQL Database from within WordPress - Wordpress Solution
[Solved] - Access Other MySQL Database from within WordPress - Wordpress Solution |
---|
Try following codes |
I have a second database that I need to access from within WordPress.
Even a simple attempt to access this database fails completely. I know I can access the database with the same code from outside of WordPress so I am assuming that WordPress is stopping my access of this external MySQL Database.
The quick code I put together for testing is as follows (sorry about crappy code - not really my calling or skillset);-
Can anyone advise how I can help me modify the above code so I can access the second MySQL database from within WordPress preferably via modification of one of my page templates. thanks in advance for any help you can offer. Solution - 1Hey, Are you trying to connect to the localhost or some external server database? Here's the code that worked for me with both connecting to localhost and remote database. I just putted it into my page.php template. Please see if this works for you? Solution - 2Is the second database in the same server where your wordpress is installed? if not, you must allow this IP (where wordpress is installed) to the mysql server. suppose, ur wordpress is installed in 192.168.1.1 and your mysql server is installed in 192.168.1.5 then you need to allow 192.168.1.1 in your mysql server. you may write the following statement in mysql console: > it is out of wordpress's capabilities to restrict any connection to your mysql server as long as your credentials are correct. thanks Solution - 3if your user have same credentiols for assecign db its a simple. 1) 2) who cares about `` 3) 2 simple ways to amke it also workable with $wpdb->update and $wpdb->insert open wp-includes/wp-db.php find function prepare($query = null) now find return @vsprintf($query, $args); replace its by return apply_filters('query', @vsprintf($query, $args)); i am assuming you have add filter for sql abouw to this code. So as you can see its prety usefull and simple. witch same credentials to make simple selects! cheers. a sample plugin for you http://www.mediafire.com/?jtmzqjzjcnt |
Date: 2022-10-21 05:22:33 |
Category: Wordpress |