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)
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'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!
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.
I am new to PHP MVC CI and
I am getting below error.
Message: mysqli::real_connect(): php_network_getaddresses: getaddrinfo
failed: No such host is known.
Below is my info being passed.
hostname:http://localhost:1234/Sample/
username:root
password: //here Password is blank
database:codeignitordb
port:1234
Function
$mysqli->real_connect($hostname,
$this->username,
$this->password,
$this->database,
$port,
$socket,
$client_flags);
here $socket and $client_flags are Null
Question: Am I missing something ?
Hostname should be localhost only instead of http://localhost:1234/Sample/
This change should be done in database.config.
Try using 127.0.0.1
or
localhost
as your hostname
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);