Here is the PHP code which I have written :
<?php
$con=mysqli_connect("193.167.138.9","username","password","DatabaseName");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$t_name = mysqli_real_escape_string($con, $_POST['name']);
$t_email = mysqli_real_escape_string($con, $_POST['email']);
//$age = mysqli_real_escape_string($con, $_POST['age']);
$ip = getenv("REMOTE_ADDR") ;
$date_time = date("l j F Y g:ia", time()- date("Z")) ;
$sql="INSERT INTO IP_TIME (Name, MAIL_ADDRESS,IP_ADDRESS,DATE_TIME)
VALUES ('$t_name', '$t_email', '$ip', '$date_time')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "Check the IP_TIME table";
mysqli_close($con);
?>
Here 193.167.138.9 is the IP of the server which I am using. Initially when I was testing it on my local machine, in the place of "193.167.138.9", it was "localhost.
When I try to run the code on the server, it displays the following error message.
Failed to connect to MySQL: Can't connect to MySQL server on '193.167.138.9' (111)Error:
Any idea what has gone wrong? and how can I fix it?
I checked it in the mysql config file, especially the my.conf file , which looks like below :
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#
bind-address = 127.0.0.1
Not sure what is preventing the mysql to be connected. Any help/ suggestion would be helpful