Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从Wordpress post访问外部数据库:错误\u不完整\u分块\u编码_Php_Wordpress - Fatal编程技术网

Php 从Wordpress post访问外部数据库:错误\u不完整\u分块\u编码

Php 从Wordpress post访问外部数据库:错误\u不完整\u分块\u编码,php,wordpress,Php,Wordpress,我在我的Wordpress页面中安装了“插入PHP”插件,激活了它,并将此代码放入我的页面: <p> Connection test </p> [insert_php] $mydb = new wpdb('user','pass','database','hostname'); [/insert_php] 我已经检查了用户、密码、数据库和主机名;我可以从web服务器访问数据库。这可能是Wordpress的安全设置吗?我通过登录FTP站点,将我的WP站点的index.ph

我在我的Wordpress页面中安装了“插入PHP”插件,激活了它,并将此代码放入我的页面:

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

我已经检查了用户、密码、数据库和主机名;我可以从web服务器访问数据库。这可能是Wordpress的安全设置吗?

我通过登录FTP站点,将我的WP站点的index.php重命名为index.php,并在一个新的index.php文件中提供以下代码,找到了解决方案:

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

这给出了一条更有意义的错误消息,说我的用户被拒绝访问。因此,我输入phpmyadmin,并运行一个查询来查找主机名,然后在终端中以该主机名为参数调用nslookup。瞧,网络主机改变了数据库服务器的IP地址(我试着只使用主机名,但这是一个共享主机,而我使用一个临时URL似乎把这件事搞砸了)


因此,我修复了IP地址,最终可以使用数据库在Wordpress中连接和填充我的表单。干杯

你在谷歌上用过这个关键词吗?例如,这篇文章出现了:当然,还添加了Wordpress关键字。。。但到目前为止,我还没有发现类似的情况
<!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>