连接失败:php_network_getaddresses:getaddrinfo失败:名称或服务未知 [英] Getting connection failed: php_network_getaddresses: getaddrinfo failed: Name or service not known
问题描述
我正在使用POST方法向服务器上的db插入一些数据.这是我的connection.php文件,存储在我的
Im using POST method to insert some data to db on my server.This is my connection.php file that is stored in my http://www.url.com/public_html.
<?php
$servername = "http://www.url.com";
$username = "db_username";
$password = "db_password";
$databaseName = "db_name";
$connect = new mysqli($servername,$username,$password,$databaseName);
if ($connect->connect_error) {
die("Connection failed: " . $connect->connect_error);
}
echo "Connected successfully";
?>
这是insert.php文件,也存储在 http://www.url.com/public_html 中我用来在数据库中插入数据.
This is insert.php file also stored in http://www.url.com/public_html that i use to insert data in database.
<?php
if($_SERVER["REQUEST_METHOD"]=="POST"){
require'connection.php';
createStudent();
}
function createStudent(){
global $connect;
$name = $_POST["name"];
$lastname = $_POST["lastname"];
$age = $_POST["age"];
$query="INSERT INTO `demo` ( `name` , `lastname` , `age` )
VALUES ('$name','$lastname','$age')";
mysqli_query($connect,$query)or die (mysqli_error($connect));
mysqli_close($connect);
}
?>
我使用邮差和我的android应用程序对此进行测试,但即时通讯得到: 连接失败:php_network_getaddresses:getaddrinfo失败:名称或服务未知错误.
I use postman, and my android app to test this but im getting: Connection failed: php_network_getaddresses: getaddrinfo failed: Name or service not known error.
我不是PHP开发人员,但我在php文件中看不到任何错误,因此欢迎您提供任何帮助.
Im not a php developer but i can't see any error in my php files, so any help will be welcomed.
提前谢谢.
推荐答案
感谢Prerak,
Thanks Prerak,
这是答案,我的数据库位于同一台计算机上,因此我只需要
This is the answer, my database is on the same machine so I just needed to edit:
$servername = "localhost"
现在一切正常.
这篇关于连接失败:php_network_getaddresses:getaddrinfo失败:名称或服务未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!