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!

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

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名