I have remote server(windows server 2008) with MySql server installed,server has dedicated ip. I can connect on this server from remote php client using simple mysqli connection. But I cant connect from my home-PC using all other clients(MySqlWorkBench, C# etc).
To connect from C# I use:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string server = "servdomain.su";
string database = "dbname";
string uid = "root";
string password = "root";
string connectionString;
connectionString = "SERVER=" + server + "; PORT = 3307 ;" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
MySqlConnection connection = new MySqlConnection(connectionString);
connection.Open();
}
}
}
php code:
$host="servdomain.su:3307";
$port=;
$socket="";
$user="root";
$password="root";
$dbname="";
$q = "SHOW DATABASES";
$mysqli = new mysqli($host, 'root', 'root', 'dbname');
if ($result = $mysqli->query("SELECT * FROM incli_measurements")) {
while ($row = $result->fetch_row()) {
print_r($row);
}
}
print_r($mysqli);
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}
print_r($mysqli);
echo "4564654";
exit;
Every time I have: Unable to connect to any of the specified MySQL hosts.
It looks connection string should use PWD instead of PASSWORD. Have you tried the following?
connectionString = "SERVER=" + server + "; PORT = 3307 ;" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PWD=" + password + ";";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.