I am attempting to connect to a remote MySQL server from my local machine virtualhost using Proxifier Proxy (Socks5).
I am connect is working on Navicat, And using mysql -h 192.168.0.44 -u my_user -p -P port cmd is working too. Then I attempting using the following code:
$link = mysqli_connect('192.168.0.44', 'my_user', 'my_pwd', 'db_name', 'port');
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
} else {
echo 'Connected successfully';
}
exit();
My problem is that I am unable to connect locally using PHP, receiving the error:
mysqli_connect(): (HY000/2002): Operation timed out
It's connecting success on Navicat For Mysql And commands:
Related
I have mysql 8.0.15 for windows and I'm trying to connect from remote php webSite but always getting
2002: Connection refused
The code I use to test the connection is very simple
$dbHost = "HOST";
$dbUser = "root";
$dbPass = "password";
$dbDB = "DBNAME";
$dbPort = "9999";
echo "Conectando a $dbHost,$dbUser,$dbPass,$dbDB,$dbPort ";
$link = mysqli_connect($dbHost,$dbUser,$dbPass,$dbDB,$dbPort);
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
I also try host:port and p:host:port and always getting the same error message.
If you want to change the MySQL port, you have to edit the my.ini config-file on the MySQL server by setting port=<YOUR PREFERRED PORT>, then check if the port is forwarded and finally restart the MySQL server.
I have Apache (with PHP) and MySQL installed and running on my Raspberry Pi. I've done some simple tests with PHP, and it seems to be working. And MySQL is working perfectly from the terminal, and even another computer.
I made this PHP file:
<?php
echo("Connecting");
$connection = new mysqli("127.0.0.1", "admin", "password", "test");
if ($connection->connect_error) {
die("Connection error");
}
echo("Connection successful");
?>
Yet when I go to this page in my web browser, all I see is "Connecting". If I comment out the connection command, I see "Connecting Connection successful" in the browser.
It seems as if the PHP code stops running or hangs at the connection command.
Any ideas why I'm having this strange behavior?
Try adding these lines at the top: error_reporting(E_ALL);
ini_set('display_errors',1);
I hope You should do following
if ($connection->connect_error) {
echo "Connection error";
}else{
echo "Connection successful";
}
Try this instead
<?php
$link = mysqli_connect("127.0.0.1", "admin", "password", "test");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
?>
When running below code it shows error like this
$link = mysqli_connect($server, $user, $password, $db);
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
Warning: mysqli_connect(): Headers and client library minor version mismatch. Headers:50552 Library:50631
I am using php 7.1.2
This is my code to connect to Azure:
<?php
$servername='myproject.database.windows.net';
$username='somename';
$password='somepassword';
$database='some_db';
$conn=New mysqli($servername,$username,$password,$database);
//Connection error handling:
// echo #mysqli_ping($conn) ? 'true' : 'false';
if(mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
} else {
// echo "Connection success";
}
?>
I get the error:
Connection failed: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
I have tried launching this php from a WAMP server and from azurewebsites but both do not seem to work. It works with PDO but I have some pages already setup with mysqli_fetch_assoc queries and would like to preserve them.
Any suggestions?
I have a script that connects to a MySQL database in localhost, when I run it from the console it runs just fine, but when I run it from the web, I get this:
Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/tests/mysql.php on line 3
Error: Unable to connect to MySQL. Debugging errno: 2002 Debugging error: No such file or directory
I checked my php.ini file and it has the correct location of mysql.sock, the file exist, but php won't connect via web.
Also, I have Fedora Linux with Firewall disabled as well as SELinux, so I have no idea what can be causing this.
This is the test code I'm using:
<?php
$link = mysqli_connect("localhost", "root", "password", "my_db");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
?>
Any ideas?