• Hi,

    I have successfully installed WordPress 3.2.1 and
    have used it and read about it’s features for a couple of days.

    I have made a WordPress site with a menu and a static front page and
    the blog is on the news menu item. It works execllent!

    My problem is I have a MySQL database with about 18,000 records with info about plants and associated images.
    This database changes regularly.
    I would like to publish these records on my WordPress site.

    I would like to have a search form, search for plants and
    show a plant list.
    When I click on the plant list I want to show a detailed view
    about the plant record and show it’s images.

    How could I accomplish this?

    I don’t think importing the data to WP pages is a good idea,
    because the data changes regularly.

    Is it a good idea to extend WP with an URL like:
    https://mysite.com/?plant_id=1010
    if I want to show plant record with id 1010?

    Maybe I could use a plug-in or make a new one?

    Any help will be appreciated.

    I am an experienced programmer.

    Regards,
    Magnus Strand

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi 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:
    https://wordpress.stackexchange.com/questions/26463/connect-forms-in-wp-to-external-database

    As 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

    Thread Starter laplace1

    (@laplace1)

    Hi Alison,

    Thanks for your answer.

    I have chosen the method you describe and it works fine.

    I have created my own templates.
    Each logical group of functions is one page with a custom template
    (I have added a menu with commands in the sidebar).

    I use the Model-View-Controller design pattern where my page is the controller.
    My page gets called with an URL like e.g. https://www.example.com/?page_id=12&action=search&param=dog

    Magnus

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Publishing records from external database’ is closed to new replies.