SQLSTATE[HY000] [2002] Connection refused

Website URL

http://ghassan-hamadani.epizy.com/newCode/public/

Error Message

SELECT
  *
FROM
  `sessions`
WHERE
  `id` = RYqiJnO6ET2c2r18vw15Et1kycxqzYYFylrI0LHH
limit
  1

Other Information

I’m using Laravel 9

Your post contains no useful information in order to address the issue, please provide the database credentials which laravel uses to connect. (Censor the password)

4 Likes

Shouldn’t this part be in quotes?

(Optionally, since everything else is UPPERCASE, apply this to limit too):

SELECT
  *
FROM
  `sessions`
WHERE
  `id` = 'RYqiJnO6ET2c2r18vw15Et1kycxqzYYFylrI0LHH'
LIMIT
 1
2 Likes

Laravel removes those quotation marks when printing out the query for some reason, one simple proof would be that trying to inject SQL into it will fail.

3 Likes

Hi Mouhamad,

There is nothing wrong with the SQL statement. Connection refused simply means wrong password or wrong hosting address information from your config/database.php or .env.

Check and update the information under connections > mysql to the values provided in the client area > MySQL database. Then update the values to match those in the client area. Once that’s done, make sure your default connection is set to mysql, then try again.

Cheers!

3 Likes


this is my MySQL configuration

and this is my code in .env

DB_CONNECTION=mysql
DB_HOST=sql310.infinityfree.com
DB_PORT=3306
DB_DATABASE=epiz_23225434_gh
DB_USERNAME=epiz_23225434
DB_PASSWORD=*******

Hi Mouhamad,

Assuming you have pasted in the correct password, then you might want to check if the config/database.php file is taking values from the .env file, and update those lines if not.

Cheers!

1 Like

I changed my config/database.php to this:

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => 'sql310.infinityfree.com',
            'port' => '3306',
            'database' => 'epiz_23225434_gh',
            'username' => 'epiz_23225434',
            'password' => *******,
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ]
'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => 'sql310.infinityfree.com',
            'port' => 3306,
            'database' => 'epiz_23225434_gh',
            'username' => 'epiz_23225434',
            'password' => *******,
            // 'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ]
1 Like

still connection refused

Consider creating a new database and export/import the data over via phpMyAdmin option in the client area, plug in new values and try again.

I tried a pure PHP code to connect to the database and it worked just fine, so I don’t know what is the problem

Change this line

'url' => env('DATABASE_URL'),

to

'url' => null,

Maybe this helps.

nothing

I tried this and it’s working, but as Laravel connection is not:

$servername = "sql310.epizy.com";
$username = "epiz_23225434";
$password = "******";
$db = "epiz_23225434_gh";

// Create connection
$conn = new mysqli($servername, $username, $password, $db);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
else
echo "Connected successfully";

$sql = "SELECT * FROM sessions Where id = 'GQItf5A9rt6N3z7V2JiK2tGblkbT7De7Ag2TcavP'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    print_r($row)."<br>";
  }
} else {
  echo "0 results";
}
$conn->close();

exit();

$servername is different, try using this value instead.

I used and still connection refused

fixed,

the problem was in the cache, I just deleted my cache files, and it worked just fine :sweat_smile:

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.