How to connect to a database (unknown host, no ip) - php

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);

Related

mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known

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"));

Mysql error : mysqli_connect(): (HY000/2002): Connection refused

I have install mysql on digital ocean and trying to connect through php script and I got this error
mysqli_connect(): (HY000/2002): Connection refused in
/var/www/waev.in/signup/ajax/send_code.php on line 9 Failed to connect
to MySQL: Connection refused
What can be the issue :
my php script
<?php
include '../func/sms_function.php';
$mysql_host='{ip}';
$mysql_user='root';
$mysql_pass='********';
$my_db='wesearch_waev_user';
$con = mysqli_connect($mysql_host,$mysql_user,$mysql_pass);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
Maybe this would be
$mysql_host="localhost";// for local server
Or
$mysql_host="$ip";// if database is in remote and IP is stored in $ip
Check the port you are using on the server. MySQL needs to be running on the port 3306

Localhost php_network_getaddresses: getaddrinfo failed: No such host is known

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");
^^^^^^^^^

I want to access another server database in PHP

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.

Memcache connect throws error in cron job

When i try to connect to memcached server from a php page, it works without any problem.
Using this code
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
But when it tries to connect to server from a php script which is fired by cron job it throws this error
Warning: Memcache::connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/...../cron/acts_cron.php on line 3
Warning: Memcache::connect(): Can't connect to localhost:11211, php_network_getaddresses: getaddrinfo failed: Name or service not known (0) in /home/...../cron/acts_cron.php on line 3
Could not connect
What can cause this problem ?
Seems like you're missing an entry for localhost inside your hosts file. Try updating /etc/hosts and make sure that you got a line like the following in there:
127.0.0.1 localhost.localdomain localhost
using 127.0.0.1 instead of localhost fixed the issue.

Categories