How can I bypass error 111 MySQL in PHP connection? - php

I have bought a database MySQL to use on my domain/host.
I can connect to the database via wampserver (localhost) without problems.
But when I am trying to connect to the host website it gives me an error.
Connection failed: Can't connect to MySQL server on 'mysql-******.net' (111 "Connection refused")
My code:
<?php
$servername = "mysql-*********.net";
$username = "username8954";
$password = "dolphyn1235";
$dbname = "animals";
$dbServerPort = "26313";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $dbServerPort);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Any ideas how to solve this?

Check in your MySQL Server configuration files (my.cnf), find bind-address = 127.0.0.1 then comment them with # at the begining of the line. and then restar your MySQL.

Related

php mysql connection failed The server requested authentication method unknown to the client

$servername = "localhost";
$username = "jaskaran";
$password = "India#123";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
jaskaran has all access mysql and when i try with
mysql -u jaskaran -p it is working fine by when i try with php it does not why
error is The server requested authentication method unknown to the client
even i try this also
ALTER USER 'jaskaran'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'India#123';

Server select - MySQL / MariaDB

I have two database servers, MySQL and MariaDB, when I'm trying to connect to my local database on MySQL server, I always get "Connectionfailed: SQLSTATE[HY000] [1049] Unknown database 'ruff'". I found out, that my code is connecting into MariaDB server instead of MySQL. I can CREATE and CONNECT to any database on MariaDB.
How can I connect to MySQL server databases?
My code is:
// Creating a connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Creating a database named $dBName
$sql = "CREATE DATABASE $dBName";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully with the name newDB";
} else {
echo "Error creating database: " . $conn->error;
}
// Connecting to database named $dBName
$conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBName);
if (!$conn)
{
die("Connection fail: ".mysqli_connect_error());
}
// closing connection
$conn->close();
Adding port number after the localhost solved the problem.
$servername = "localhost:3308"; //MySQL
$servername2 = "localhost:3306"; //MariaDB

How to connect amazon RDS database using php

I get this error when I try to connect to the mysql database using php mysqli class.
I am using
OS :- windows 10
webserver :- xampp
php :- 7.3.3
it got a warning error and error message is junk.
mysqli::__construct(): (HY000/2002):
�ڑ��ς݂̌Ăяo���悪���̎��Ԃ�߂��Ă������������Ȃ��������߁A�ڑ��ł��܂���ł����B�܂��͐ڑ��ς݂̃z�X�g���������Ȃ��������߁A�m�����ꂽ�ڑ��͎��s���܂����
Using following code:
$dbServerName= "*******ap-northeast-1.rds.amazonaws.com";
$dbUsername= "example";
$dbPassword= "*******";
$dbName= "example";
// Create connection
$conn = new mysqli($dbServerName, $dbUsername, $dbPassword, $dbName);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
dbServerName is amazon.com for example,
password is * for security.

How to fix error in dbconn file when upload php mysql project to free webhosting site?

I've been trying to upload my PHP MySQL(in Dreamweaver) project to a free web-hosting site.
When I logged in, there is an error that appear in dbconn.php file.
The error is shown below:
and here's the code in my dbconn.php file:
<?php
/* php& mysqldb connection file */
$user = 1350048; //mysqlusername to db
$pass = "password"; //mysqlpassword to db
$host = "eskl.freeoda.com"; //server name or ipaddress
$dbname= 1350048; // db name in server freeoda
$dbconn= mysql_connect($host, $user, $pass);
if(isset($dbconn)){
mysql_select_db($dbname, $dbconn) or die("<center>Error: " . mysql_error() . "</center>");
}
else{
echo "<center>Error: Could not connect to the database.</center>";
}
?>
I would really appreciate if anyone can teach me how to solve this.. thanks in advance!
As Kerbholz already stated, don't use mysql_* functions, they are really outdated.
Instead use mysqli:
$servername = "eskl.freeoda.com";
$username = "1350048";
$password = "password";
$database = "1350048";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
For your error it got mostly something to do your host doesn't allow remote connections. Try to change the serverhost to localhost or 127.0.0.1

How to connect to my remote Mysql Database via Xampp

I am using Xampp to update my website and since I have added a Mysql database I have the error further down locally while it works fine online.
I'm using the code below to connect to my database:
<?php
$servername = "myservername";
$username = "myusername";
$password = "mypassword";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
http://localhost/connectdb.php
Result:
Connection failed: php_network_getaddresses: getaddrinfo failed: No
such host is known.
http://example.com/connectdb.php
Result:
Connected successfully
So there must be some configuration to do in Xampp to access a remote database or do I need to ask my host to whitelist my private IP Address? My host is OVH.
Thanks for your help

Categories