0

I am working on a payroll system. Everything is working fine on localhost (xampp) but when I upload it to ionos hosting, it is loading the admin login page fine but when i enter the username & password it is giving "Connection failed: No such file or directory".

DB name: dbs4868780

and here is the code:

<?php
    $conn = new mysqli('localhost', 'root', '', 'xxxxxxxxx');

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    
?>

EDIT:

I tried it but it is still giving the same error.

I also tried to connect DB with PHP code provided by ionos but it is still giving "Connection failed. File or Directory not found"

Here is the php code from ionos:

<?php
  $host_name = 'db5005797255.hosting-data.io';
  $database = 'dbs4868780';
  $user_name = 'xxxxxxxxx';
  $password = 'xxxxxxxxxxxxxxxxxxxx';

  $link = new mysqli($host_name, $user_name, $password, $database);
  if ($link->connect_error) {
    die('<p>Failed to connect to MySQL: '. $link->connect_error .'</p>');
  } else {
    echo '<p>Connection to MySQL server successfully established.</p>';
  }
?>

  • 2
    You might need to check where the database is hosted. It might be in another server, not ``localhost``. – Dula Nov 16 '21 at 01:12
  • Check here - https://www.ionos.com/help/hosting/using-mysql-databases-for-web-projects/finding-mysql-access-data-in-the-control-panel/ – Dula Nov 16 '21 at 01:14
  • 3
    create a user for the database and not to use root user please – Ken Lee Nov 16 '21 at 01:45
  • 1
    Even if your database is local it's never a good idea to post the password publically. I removed it but you should change it anyway. – Cfreak Nov 16 '21 at 03:31

1 Answers1

1

enter image description here

See attached fake database example to get your data

Peneh
  • 195
  • 1
  • 10
  • I tried it but it is still giving the same error. ``` – user2965100 Nov 16 '21 at 19:18
  • Seems to work, at my end. What error are you getting? – Peneh Nov 16 '21 at 19:57
  • Are you trying to connect from your local environment? (xampp etc.) if yes, check this out https://www.ionos.com/help/server-cloud-infrastructure/dedicated-server-for-servers-purchased-before-102818/administration-of-linux-servers/allow-external-access-to-mysql-server/ – Peneh Nov 16 '21 at 20:07