I'm sitting on a MacOS High Sierra(v10.13.1) and I followed a guide to install/enable Apache2, PHP7, MySQL and PhpMyAdmin locally.
The guide I followed:
https://coolestguidesontheplanet.com/install-apache-mysql-php-and-phpmyadmin-on-macos-high-sierra-10-13/).
I thought everything worked since I can log in to PhpMyAdmin with my root account and have access to create databases etc.. But trying to connect to my database in PHP I get this error:
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Users/.../Sites/BattleriteTracker/include/base/Database.php on line 7
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Users/.../Sites/BattleriteTracker/include/base/Database.php on line 7
Mysql connection error: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
The code I used to connect with:
$Adress = "localhost";
$User = "root";
$Password = "...";
$Name = "BattleriteTracker";
$Connect = new mysqli($Name, $User, $Password, $Name);
if($Connect->connect_errno)
{
die("Mysql connection error: " . $Connect->connect_error);
}
Some additional info about my versions:
Apache: 2.4.27
MySQL: 5.7.20
PhpMyAdmin: 4.7.5
If anyone of you know what the problem is, please enlighten me.
Thanks for reading!
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"));
I am using mysql database, I was deploying my database with some hosting company and it was working fine but they suck so I migrated to upCloud. now I am facing a problem connecting to the database and getting an error:
Connection failed: SQLSTATE[HY000] [2002] php_network_getaddresses:
getaddrinfo failed: Name or service not known
$servername = 'localhost';
$username = "root";
$password = "password";
$database = 'dbname';
try{
$conn = new PDO("mysql:host=localhost;dbname=driver", $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();
}
I tried changing localhost to 127.0.0.1 but no luck, I also tried manipulating single quote and double quote in strings but also it didn't work. can you advise on why I am getting this error?
I am deploying this in Ubonto 16.04
Double check your DB connection details (host, DB name, username and password).
If it still does not work, then apparently there is a bug recently discovered and reported on Ubuntu, which fixes itself if you restart your Server.
More details are listed here:
Bug reported at Ubuntu:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1674733
Another StackOverflow link where this issue is reported and discussed:
PDOException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
Hope it helps :)
EDIT:
Ubuntu has apparently released a fix as well: https://www.ubuntu.com/usn/usn-3239-2/
Update your version of Ubuntu and libraries as listed at this page.
This question already has answers here:
php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not knownfailed?
(2 answers)
Closed 1 year ago.
I am getting following error from the my sql server installed in localhost.
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Users/asif/Sites/ver1/php_includes/db_conx.php on line 2
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Users/asif/Sites/ver1/php_includes/db_conx.php on line 2
php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not knownYYYYYYYYYYYYY
I am using following in the connect string:
<?php
$db_conx = mysqli_connect(“localhost”, “root”, "xxxxxx", "elearning");
// Evaluate the connection
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
echo "YYYYYYYYYYYYY";
exit();
}
mysqli_query($db_conx, "SET NAMES UTF8");
?>
For information I can login with the password and username through phpmyadmin. Suggesting a remedy would be highly appreciated.
The quotes on localhost and root look weird, those are not normal quotes, if you use those I'm sure it won't work, also try setting variables before the con add use them to connect
Try Using
$db_conx = mysqli_connect("localhost", "root", "", "test");
//$db_conx = mysqli_connect("HostName", "UserName", "Password", "DatabaseName");
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)