Forum Replies Created

Viewing 5 replies - 241 through 245 (of 245 total)
  • Forum: Plugins
    In reply to: Including wp-config.php
    Thread Starter jalenack

    (@jalenack)

    Alright, I’ve made some progress. I’ve managed to move everything into one big file that is activated in the plugin and that works great…so I can now use the $wpdb variable without problems….err…I can now receive the $wpdb, whereas before I couldn’t. Now, I’m still struggling with how it works. I’ve spent a lot of time looking at other plugins, but I’m still not getting it. Below is an example of how it is set up now…

    // establishes a connection to a mySQL Database accroding to the details specified in db.php
    function getDBConnection () {
    include("db.php" ); // contains the variables below >:-(
    $conn = mysql_connect($server, $loginsql, $passsql);
    if (!$conn) {
    echo "Connection to DB was not possible!";
    end;
    }
    if (!mysql_select_db($base, $conn)) {
    echo "No DB with that name seems to exist at the server!";
    end;
    }
    return $conn;
    }

    // retrieves all messages with an id greater than $lastID
    function getData($lastID) {
    $sql = "SELECT * FROM wp_liveshoutbox WHERE id > ".$lastID." ORDER BY id ASC LIMIT 60";
    $conn = getDBConnection();
    $results = mysql_query($sql, $conn);
    if (!$results || empty($results)) {
    //echo 'There was an error creating the entry';
    end;
    }
    while ($row = mysql_fetch_array($results)) {
    //the result is converted from the db setup (see initDB.php)
    $name = $row[2];
    $text = $row[3];
    $id = $row[0];
    if ($name == '') {
    $name = 'no name';
    }
    if ($text == '') {
    $name = 'no message';
    }
    echo $id." ---".$name." ---".$text." ---"; // --- is being used to separete the fields in the output
    }
    }

    Thank you all so much for your help

    Forum: Plugins
    In reply to: Including wp-config.php
    Thread Starter jalenack

    (@jalenack)

    I haven’t figured out how to access the $wpdb variable…

    Forum: Plugins
    In reply to: Including wp-config.php
    Thread Starter jalenack

    (@jalenack)

    MMmm, still not working.

    I’ve uploaded a copy of the current files (in a .zip) at
    https://blog.jalenack.com/live.zip

    It’s relatively complete, but you’re the very first ones to see it so be careful. I wrote up an installation process in the readme.txt . Installation is pretty standard. Again, this has never been tested outside of my blog, so I’m not guaranteeing anything. For reference on how it should work, https://blog.jalenack.com has it running.

    Anyways, my problem continues. Using ColdForged’s code (alpahoide, I wish it were that easy..that’s the first thing I tried), I managed to include it just fine and even managed to print the $server, $loginsql, $passsql, and $base variables to a blank browser. However, it still won’t work with my plugin.

    It may be a conflict with the inclusion of other files from wp-config.php, such as wp-blog-header.php

    I think I may need to just restructure somehow, so that I can use the $wpdb variable in some way. Thoughts?

    Forum: Plugins
    In reply to: Including wp-config.php
    Thread Starter jalenack

    (@jalenack)

    Sorry, I’m still having a bit of trouble.

    Here’s how it is currently set up, everything in one folder within the /wp-content/plugins/ folder:

    There is the main plugin file with a single function that will print the html for my plugin to a page. There is nothing else in that file.

    Next, there is a javascript file that runs the AJAX backend and calls two separate php files at different times, one for sending information and one for receiving it.

    These separate php files need to connect to the database. Currently it uses a separate include file with the database login information, identical to that found in the wp-config file.
    Obviously, that’s pain, and I’d like to just use the wp-config information.

    The problem is, the 2 get and send php scripts are not connected with WordPress, so they can’t receive the global$wpdb. So the most convenient way would be to just include the wp-config file..but I don’t think that’ll work. Should I integrate some of the files, and if so, how? Any ideas on how to get the database info?

    Forum: Plugins
    In reply to: Including wp-config.php
    Thread Starter jalenack

    (@jalenack)

    Ok, let me rephrase…

    How can plugins access the main database?

Viewing 5 replies - 241 through 245 (of 245 total)