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
Related
<?php
$conn = new mysqli('localhost','root', '', 'votesystem','8080');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
Errors returned are:
Warning: mysqli::__construct(): Error while reading greeting packet. PID=14576 in
C:\xampp\htdocs\votesystem\admin\includes\conn.php on line 2
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone away in
C:\xampp\htdocs\votesystem\admin\includes\conn.php on line 2
Fatal error: Maximum execution time of 120 seconds exceeded in
C:\xampp\htdocs\votesystem\admin\includes\conn.php on line 2
My localhost runs on port 8080.
username-root
hostname=localhost
password=no
global privileges=ALL
PRIVILEGES Grant= yes
You have confused the Webserver with the MySQL Server. Your web server is running on port 8080, not your MySQL Server. The MySQL server runs on port 3306 (by default) so your web application needs to connect to it on that port.
Change your mysqli connect string to:
$conn = new mysqli('localhost','root', '', 'votesystem', '3306');
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2003):
Can't connect to MySQL server on '209...' (13) in
/home/www/hookahondemond.com/Sendorder01010101010101.php on line 77
Failed to connect to MySQL: Can't connect to MySQL server on
'209...' (13)
my php code
<?php
$con=mysqli_connect("209.17.116.155","mir****","M****6","stores",'3306');
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
Login to Apache/PHP server and make sure that you can connect to the MySQL port:
telnet <mysql host> <mysql port>
If you cannot telnet the port, then it could be either one of these:
a network (firewall? routing?) problem
your MySQL server is currently not running
your MySQL host/port is incorrect
your MySQL is running but does not accept tcp connections (it has --skip-networking option set)
If you can telnet the MySQL host/port, then there is no network/MySQL setting problem,
and actually, you should be seeing a different error message (like credential error)
I want to echo or print content from a database in my terminal on my raspberry pi. I installed MySql client and PHP5. I want to run a php file in my terminal so i created a file:
<?php
$con = mysqli_connect("mysql51-025.wc1","username","password","dbname")
//first one is hostname
if(mysqli_connect_errno()){
echo "failed to connect with error: ". mysqli_connect_error();
}
?>
When i run this in my terminal on my raspberrypi
pi#raspberrypi ~ $ php database.php
I'll get this returned:
PHP warning: mysqli_connect(): (hy000/2005): Unknown MySQL server host
'nameofmyhostinphpfile' (25) in /home/pi/database.php on line 8
failed to connect with error: Unknown MySql server host 'hostname'
My question is how i can make this connection work. And will i be able to execute queries and echo or print those results on my pi and use those results in shell scripts?
Thank you!
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.