I am using Localhost with UniServer, running Apache and MySQL. (There is no username or password)
I have the code new mysqli("http://localhost/us_phpmyadmin/","","","url_short"); to connect to my Localhost server, but when I try to run the code mysqli_query("INSERT INTO cut.it VALUES (NULL, $longurl, $shorturl)");
, the error php_network_getaddresses: getaddrinfo failed: No such host is known. comes up on the page. Why is this and how can I get around it?
You have to specify the hostname of MySQL instance not a url for phpMyAdmin.
Change
... mysqli("http://localhost/us_phpmyadmin/","","","url_short");
to
... mysqli("localhost", "", "", "url_short");
^^^^^^^^^
Related
I am trying to connect my local PHP program from one PC and Mysql from a server or another PC. But I got following error when I tried this
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\xampp\htdocs\bharat\bharat\connect.php
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\xampp\htdocs\bharat\bharat\connect.php
Warning: mysqli_error() expects parameter 1 to be mysqli, string given in D:\xampp\htdocs\bharat\bharat\connect.php
<?php
$con = mysqli_connect('https://192.168.43.215', 'root', '12345678', 'bharat') or die(mysqli_error("Error connection"));
I tried to keep mysql database in remote server for data security and software in local machine. Can any one tell me the exact way. Thank you.
You don't need the https://, this would be sufficient:
<?php
$con = mysqli_connect('192.168.43.215', 'root', '12345678', 'bharat') or die(mysqli_error("Error connection"));
So I keep sporadically getting the following error:
Type: PDOException
Code: 2002
Message: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
File: /var/www/html/system/db.php
Line: 71
It started randomly after no particular event. I haven't changed anything relating to the database connection etc. I will make some requests, and it will be working fine, then will get this for a few seconds / minutes, then it will go back to working again.
$this->connection = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS);
My host is similar to the following. Its a subdomain from my ISP, which shouldnt make any difference.
define("DB_SERVER", "name.plus.com:3306");
The machine is self hosted, so no AWS as this similar question here - "PDO exception: php_network_getaddresses: getaddrinfo failed" after changing DNS resolvers, with DB running on AWS
Its running on some docker containers. I have rebooted the actual machine too.
Why would it just randomly be unable to resolve that domain at certain points, and then work fine?
I have a database hosted by one.com with these settings:
PhpMyAdmin: https://dbadmin.one.com
Host: axelerate.be.mysql
Database: axelerate_be
Username: axelerate_be
Password: *****
I want to make connection with this database by using a php file runned by the LXTerminal of the raspberry pi. When i try to make connection i get this error (host unknown):
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo
failed: Host is onbekend. in C:\xampp\htdocs\twitter\index.php on line
3
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses:
getaddrinfo failed: Host is onbekend. in
C:\xampp\htdocs\twitter\index.php on line 3 Failed to connect to
MySQL: php_network_getaddresses: getaddrinfo failed: Host is onbekend.
This is my code:
<?php
// Create connection
$con=mysqli_connect("axelerate.be.mysql","axelerate_be","*******","axelerate_be");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
echo "it works!";
}
?>
My question:
How can i make this connection work without edditing any config files? (so if there is something to do, I want only to write in the php file)
Thanks!
The .mysql based hosts are internal hosts within the one.com network that resolves to the server that hosts your database. These hosts are not meant for connections outside of one.com hosting, and probably doesn't accept connections from the world if they're even available on a public IP.
Make sure the host (axelerate.be.mysql) exists, try to ping it. AS i can see it doesnt exist.
One.com doesn't support mysqli. You have to use
$db=mysql_connect("example.com.mysql", "username", "password");
mysql_select_db("database", $db);
I am really a beginner in PHP and Mysql. I made a database on static IP 192.168.1.211 which is based on CentOS(only Command prompt) and on this IP there is no other software like easyPHP, and I am working on static IP 192.168.1.20 based on Windows 7. I also installed easyPHP and Dreamweaver... using Dreamweaver I made one .php file and I tried to use the database which is on 192.168.1.20..
using below code
<?php
$server2 = '192.168.1.211';
$con = mysqli_connect(server2,'root','password','vvani');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
but I get an error as shown below
Notice: Use of undefined constant server2 - assumed 'server2' in C:\Program Files\EasyPHP-DevServer-13.1VC9\data\localweb\test\welcome.php on line 4
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Program Files\EasyPHP-DevServer-13.1VC9\data\localweb\test\welcome.php on line 4
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Program Files\EasyPHP-DevServer-13.1VC9\data\localweb\test\welcome.php on line 4
Failed to connect to MySQL: php_network_getaddresses: getaddrinfo failed: No such host is known.
How can I access the database on 192.168.1.211 from 192.168.1.20 in PHP code?
I also tried hard to find a solution from Google, but I am not getting a perfect solution.
Just read errors and correct it..
<?php
$server2 = '192.168.1.211';
$con = mysqli_connect($server2,'root','password','vvani'); // here, $server2 is variable, not constant
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
Change server2 to $server2. If that still doesn't work then it's possible the other server does not allow requests in such a way so you will have to update the MySQL settings on that server to allow external access to the port (or otherwise forward it).
Thanks Elon Than and Explosion Pills,
I changed server2 to $server2, but I get new warning
Warning: mysqli_connect(): (HY000/1130): Host '192.168.1.20' is not allowed to connect to this MySQL server in C:\Program Files\EasyPHP-DevServer-13.1VC9\data\localweb\test\welcome.php on line 4
And I research on it and I try to give remotely access to database on another server.
Follow some few steps and solved problem.
# mysql -u root -p
mysql> GRANT ALL ON Database.* TO <un>#'localhost' IDENTIFIED BY 'password';
Thanks again.
I am trying to connect to RDS from my localhost and ec2 server.
I can connect fine with MySQL Workbench 5.2 CE but i cant seem to connect with PHP.
They are in the same zone and security group.
$dbName = "*******-****.***************.**-****-*.rds.amazonaws.com:3306";
$dbTable = "myTable";
$dbUser = "myUser";
$dbPass = "*********";
define("HOST", $dbName);
define("DBUSER", $dbUser);
define("PASS", $dbPass);
define("DB", $dbTable);
$conn = new mysqli(HOST, DBUSER, PASS, DB) or die();
these are the errors
Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: php_network_getaddresses: getaddrinfo failed: No such host is known.
Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (trying to connect via tcp://*******-****.***************.**-****-*.rds.amazonaws.com:3306)
Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known.
the endpoint works fine as i said with the client, not on browser.
but what does this error mean, and how would i start debugging this?
Have you checked the security group for your amazon ec2 in your amazon admin console. please check you have opened the port for mysql (i.e 3306)