chiurlo
Forum Replies Created
-
Forum: Plugins
In reply to: Publishing records from external databaseHi Magnus,
I’m not sure I can answer all the parts of your question, but as for connecting to an external database, you could try this:
1) Create a config file and save it in the same directory as wp-config.php (I figure that must be good and secure!).
2) In that file, define your DB connection variables, e.g.:/** MySQL hostname */ define('DB_HOST_SSOS', 'enter_hostname_here'); /** MySQL database name */ define('DB_NAME_SSOS', 'enter_dbname_here'); /** MySQL database username */ define('DB_USER_SSOS', 'enter_dbusername_here'); /** MySQL database password */ define('DB_PASSWORD_SSOS', 'enter_dbpassword_here');3) At the top of the file from which you need to establish the DB connection, do something like this (assumes the file is in the theme folder):
if (!require_once("../../../myconfig.cfg")) { echo "inc failed"; } $con = mysql_connect(DB_HOST_SSOS,DB_USER_SSOS,DB_PASSWORD_SSOS); // server, user, password if (!$con) { die('Sorry, could not connect: ' . mysql_error()); } $db_selected = mysql_select_db("ssos", $con); if (!$db_selected) { die ("Can\'t use test_db : " . mysql_error()); }Alternately, follow the approach given here, which makes use of the wpdb class. I decided against this approach because I was concerned that it might interfere with the correct functioning of the rest of the application:
http://wordpress.stackexchange.com/questions/26463/connect-forms-in-wp-to-external-databaseAs for extending the URL with your custom query parameter, I can’t off the top of my head think of a reason why not, but hopefully someone else will correct me if I’m wrong!
As for whether to make/use a plugin, I don’t see that that would be necessary unless you thought it likely that you’d like to reuse the same functionality in a different WP site.
Hope this helps!
All best,
Alison