0

I installed the "Insert PHP" plugin in my Wordpress page, activated it, and put this code in my page:

<p> Connection test </p>
[insert_php]
$mydb = new wpdb('user','pass','database','hostname');
[/insert_php]

When I try to load the page, it loads for a long time and stops short. Then I see the following error in the Chrome console:

GET [my_site_url] net::ERR_INCOMPLETE_CHUNKED_ENCODING

I already checked user, pass, database and hostname; I can access the database from the web server. Could it be some Wordpress security setting?

  • Have you tested the PHP plugin with something simpler? For example echo "hello world";. – Burgi Nov 2 '15 at 11:45
  • Have you searched for the error? There are multiple results and they don't seem to be WordPress related. – s_ha_dum Nov 2 '15 at 13:47
  • @Burgi: Yes, it works fine unless I try to access the external db – dario_ramos Nov 2 '15 at 14:14
  • @s_ha_dum: Extensively. I also asked at #wordpress IRC and all they were able to tell me was that it may be some server config issue. But I don't have the slightest idea of where to look, and the customer support people from the hosting service are utterly useless. They just gave me FTP and CPanel access and left me on my own. My last idea is to create a test PHP page that only access the database and see if it crashes in the same way. But even if it does, I just have no idea how to fix it. – dario_ramos Nov 2 '15 at 14:16
  • Apologies, @dario_ramos, but it does look like a server issue to me (per virtually all of the Google results, plus the fact that the problem occurs with a remote connection and only then). There are numerous suggested solution in those search results, but the correct answer depends on server (Apache? Nginx? What?) and server configuration. – s_ha_dum Nov 2 '15 at 14:20
0

I found the solution by logging into the site FTP, renaming my WP site's index.php to index.php_, and supplying this code in a new index.php file:

<!DOCTYPE html>
<html>
<body>

<?php
$servername = "xxx.xxx.xxx.xxx";
$username = "xxxxx";
$password = "xxxxx";

try {
    $conn = new PDO("mysql:host=$servername;dbname=xxxxxx", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
?>

</body>
</html>

This gave a far more meaningful error message, saying that access was denied for my user. So I entered phpmyadmin, and ran a query to find the host name, and then called nslookup in a terminal with that host name as argument. And lo and behold, the web hosting had changed the database server IP address (I had tried to work with just the hostname, but this being a shared hosting and me using a temporary URL seems to botch that way of doing it).

So I fixed the IP address and I finally could connect and populate my forms in Wordpress using the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.