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!

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

报告相同问题?

悬赏问题

  • ¥20 Apache poi使用问题
  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素
  • ¥15 stc12c5a60s2、QMC5883L、LCD1602组合测量磁场所需程序
  • ¥20 Win11测试yolov4,“找不到nvcuda.dll”怎么办?
  • ¥15 simulink绘制bode图
  • ¥15 php_network_getaddresses: getaddrinfo failed: Name or service not known
  • ¥15 用msg发消息出现的问题
  • ¥15 unity3d机械臂