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 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档