• Hi there,

    I am building a new WP site and want to create a couple of pages that access data from a separate mysql database. I want to insert the PHP into the pages using a plugin like Insert PHP.

    I’ve installed the plugin but, I cannot seem to get the database to connect from within the WP page.

    First off, I am not even sure where to put the second mysql file on the same server. It has a different login and PW than the WP site.

    Should I put it in the \var\www\html folder? I don’t want to replace the DB I am using, just send some queries out to another one on the same server to get some data.

    I’ve added PHP with the insert PHP plugin and I get an access denied message:

    Connection failed: Access denied for user ‘root’@’localhost’

    Here is the code I use:

    $servername = “localhost”;
    $username = “xxxx”;
    $password = “xxxx”;
    $dbname = “xxxx”;

    // Create connection
    $conn = new mysqli($servername, $username, $password);
    // Check connection
    if ($conn->connect_error) {
    die(“Connection failed: ” . $conn->connect_error);
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WillBontrager

    (@willbontrager)

    Unfortunately, I’m unprepared to help you with database connections or PHP coding.

    Let me suggest this: Make a separate php page that does what you want to do with Insert PHP. Figure out how to connect to MySQL and how to use it.

    When the separate php page is working the way you want it to work, then put the relevant code into your WordPress page between Insert PHP tags.

    If it works in the separate php page and doesn’t work when the code is between Insert PHP tags, then perhaps I can help you.

    Will

    Dear Will,

    I have the same problem with connecting to MySQL Database.
    My code was running on my first website using Avada Theme from version 3 and is still running with Avada updates.
    Now I have to create another website, and I bought another Avada Theme version 5.2
    I copied paste my code running from the first site and it does not run. Actually, the simple routine as follow does not work :
    mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db (DB_NAME);
    mysql_close();

    I get a message like “error 500”.
    So my question is : does this plug-in is updated to work with Avada Theme 5.2? If not, can you tell me if it will be and when?

    I really like this plug-in and I don’t plan to look for another solution to run some PHP codes in my pages.

    Kind Regards

    Plugin Author WillBontrager

    (@willbontrager)

    Error 500 means Internal Server Error. There’s something wrong in your code, somehow.

    Make a stand-alone PHP page with the connection code. When you get that working, it should work with Insert PHP.

    Insert PHP is not and won’t be modified to work with specific themes. It would be a never-ending race to keep up and I’m unwilling to enter that race for a free download.

    It’s not a theme issue, actually, unless the theme or interface changes the PHP code you paste between the insert_php codes.

    Make a stand-alone page and get the code working in it.

    Will

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Connect and Query MySQL Database’ is closed to new replies.