1

Here is my code:

$dbServername = "localhost:3306"; //I also tried localhost, localhost:8080, 127.0.0.1
$dbUsername = "root1"; //new user created in myphpadmin
$dbPassword = "mypassword"; //I used a new password for the above user
$dbName = "loginsystem"; //the database exists in myphpadmin

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

if (!$conn) {
    die('error connecting to database');
    }

echo 'you have connected successfully';

For the dbServername, I've tried using localhost, localhost:8080, localhost:3306 and 127.0.0.1, but only 127.0.0.1 and localhost:3306 seem to go through and gives me the error at stake. I get different errors with localhost (No such file or directory*) and localhost:8080 (MySQL has gone away).

So given the IP as dbServername seems to passthrough and go to username and password check, I assume this is right. But then I get the error Access denied for user 'root'@'localhost'.

The username root without password exists is valid myphp. The database loginsystem also exists. I tried create new usernames and passwords and connect with this and it didn't work.

Edit01: I am using iOS. The users in mysql.user are 'root' without password, and I created one called 'root1' with a password to test. These 2 do not work when I tried them in my variables. I tried create new users names and restart MySQL after creation. I also re-created my database. I have XAMPP running here: /Users/jpb/.bitnami/stackman/machines/xampp/volumes/root/htdocs/wsd/includes/dbh.inc.php.

Edit02: Added a screenshot of my user accounts overview: click here to view

*Warning: mysqli_connect(): (HY000/2002): No such file or directory in /Users/jpb/.bitnami/stackman/machines/xampp/volumes/root/htdocs/wsd/includes/dbh.inc.php on line 8

I am running out of ideas. Hope you can help. Thank you

Edit03: I removed and un-installed XAMPP and MySQL. I installed AMPPS and now everything is fine: 'Success: A proper connection to MySQL was made. Host information: localhost:3306 via TCP/IP'. Thank you to those who helped and let me know if you run through similar issues, maybe I can help.

JPB
  • 11
  • 4
  • Which operating system are you using? Where is PHP running? Where is MySQL running? What accounts are in your `mysql.user` table? Have you restarted MySQL after you have changed any login?Please edit your question to include the relevant informations about your system/setup. – Progman Jul 20 '18 at 21:35
  • Thank you @Progman. I am using IOS. The users in mysql.user are 'root' without password, and I created one called 'root1' with a password to test. These 2 do not work when I tried them in my variables. I tried create new users names and restart MySQL after creation. I have XAMPP running here: /Users/jpb/.bitnami/stackman/machines/xampp/volumes/root/htdocs/wsd/includes/dbh.inc.php. I will edit my above question with this information. – JPB Jul 21 '18 at 08:25
  • Keep in mind that `localhost` and `127.0.0.1` are different logins in MySQL, see https://stackoverflow.com/questions/19712307/mysql-localhost-127-0-0-1 – Progman Jul 21 '18 at 10:30
  • Yes thank you @Progman. My database user (root) in myphp is associated with localhost. When I run the code with **localhost** only, I get 'No such file or directory' error. When I run the code with **localhost:3306**, I get 'Access denied for user 'root'@'localhost''. – JPB Jul 21 '18 at 10:59
  • Please edit your question to include the content of your `mysql.user` table. – Progman Jul 21 '18 at 11:13
  • @Progman. I've edited the question now with the user table. Thank you – JPB Jul 21 '18 at 11:34
  • When you use `localhost` you have to use `localhost` on your login, without using any port number. What is the complete "No such file or directory" error message you get when you try? – Progman Jul 21 '18 at 12:06
  • @Progman. Here is the full message I get: Warning: mysqli_connect(): (HY000/2002): No such file or directory in /Users/jpb/.bitnami/stackman/machines/xampp/volumes/root/htdocs/wsd/includes/dbh.inc.php on line 8. I will edit my message:). Thanks again – JPB Jul 21 '18 at 12:57
  • Possible duplicate of [My database user exists, but I still get an (HY000/2002): No such file or directory](https://stackoverflow.com/questions/20073168/my-database-user-exists-but-i-still-get-an-hy000-2002-no-such-file-or-direct) – Progman Jul 21 '18 at 12:58
  • Thank you again @Progman. I had already been through this question and tried what they tried including modifying php.ini. But I'm still in the same situation. – JPB Jul 21 '18 at 13:18
  • If you want to connect to MySQL using the system provide socket functionality, you have to specify the socket path in the php.ini and in the MySQL server configuration. If you want to connect to MySQL using an IP address you have to add a user for the host `127.0.0.1` and use `127.0.0.1` for the connection as well. – Progman Jul 21 '18 at 13:28
  • Hi @Progman, it's me again. I tried using **127.0.0.1** with a new user as you can see in the updated User Table on Edit02 of my post. My code is all updated accordingly and it still doesn't work. Let me know if you have other ideas. Otherwise, I am not sure what to do when you say 'specify the socket path' - I have found **default_socket=** in php.ini but not sure what to write there. Hope you can still help me, thanks. – JPB Jul 27 '18 at 15:32

1 Answers1

-1

Make clear your user "root" have access for login, an you use the correct host-adress. Try to change to an other user to access. enter image description here

  • Thank you @Janick Koder. In myphp, my 'root' user has ALL PRIVILEGES, and the HOST NAME is localhost. I tried to create and connect to new users and it also did not work. – JPB Jul 21 '18 at 07:52