douhuang1852 2015-11-02 07:46
浏览 64
已采纳

从Wordpress帖子访问外部数据库:ERR_INCOMPLETE_CHUNKED_ENCODING

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?

  • 写回答

1条回答 默认 最新

  • doumeng3188 2015-11-03 04:13
    关注

    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. Cheers!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?