I think I got it working again. By forcing the port being used to 80 for apache, and 3306 for mysql. I killed the processes that occupies those port.
This is the exact error showing
<br />
<b>Fatal error</b>: Uncaught mysqli_sql_exception: Access denied for user 'root'@'localhost' (using password: NO) in C:\xampp\htdocs\pcss\public\config\endpoints\db.php:16 Stack trace: #0 C:\xampp\htdocs\pcss\public\config\endpoints\db.php(16): mysqli->__construct('localhost', 'root', Object(SensitiveParameterValue), 'pcss') #1 C:\xampp\htdocs\pcss\public\components\medical-records.php(2): include('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\pcss\public\index.php(28): include('C:\\xampp\\htdocs...') #3 {main} thrown in C:\xampp\htdocs\pcss\public\config\endpoints\db.php on line 16
and these are the relevant codes
//C:\xampp\htdocs\pcss\public\config\endpoints\db.php
<?php
$servername = "localhost";
switch($_SERVER['HTTP_HOST']){
//this case part is modified, shouldnt matter i think
case "my website's link in 000webhost":
$username = "lorem";
$password = "lorem";
$database = "lorem";
break;
//this default part is not modified
default:
$username = "root";
$password = "";
$database = "pcss";
}
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
?>
C:\xampp\htdocs\pcss\public\components\medical-records.php(2)
include("config/endpoints/db.php");
It used to work just fine until I reformatted my laptop. I even have a website running on 000webhost able to connect w/ MySQL there right now, and all other test files I've done have the same local credentials of
$servername = "localhost";
$username = "root";
$password = "";
and I can login with the shell command 'mysql -u root -p -h localhost' and pressing enter again when prompted for a password,
and I can control the users, databases, and etc... in phpMyAdmin.
Tried these:
"Connect failed: Access denied for user 'root'@'localhost' (using password: YES)" from php function
MySQL said: Documentation #1045 - Access denied for user 'root'@'localhost' (using password: NO)
MySQL Error: : 'Access denied for user 'root'@'localhost'
I've tried the alter thing, basically changes the password of the user you are pointing at. Still don't work. I supposed you should do these stuffs if you can't access phpMyAdmin/MySQL to begin with.
I made a new user account with these credentials just to test:
User name: 'restapi'
Password: 'restapi'
I can login with it in shell's cmd w/ 'mysql -u restapi -p -h localhost', and typing 'restapi' again when prompted for a password. Still can't connect with mysql tho. This is the error:
Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'restapi'@'localhost' (using password: YES) in C:\xampp\htdocs\pcss\public\config\endpoints\db.php:16 Stack trace: #0 C:\xampp\htdocs\pcss\public\config\endpoints\db.php(16): mysqli->__construct('localhost', 'restapi', Object(SensitiveParameterValue), 'pcss') #1 C:\xampp\htdocs\pcss\public\components\medical-records.php(2): include('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\pcss\public\index.php(28): include('C:\\xampp\\htdocs...') #3 {main} thrown in C:\xampp\htdocs\pcss\public\config\endpoints\db.php on line 16
and this is the code with that new user account:
//C:\xampp\htdocs\pcss\public\config\endpoints\db.php
<?php
$servername = "localhost";
switch($_SERVER['HTTP_HOST']){
//this case part is modified, shouldnt matter i think
case "my website's link in 000webhost":
$username = "lorem";
$password = "lorem";
$database = "lorem";
break;
//this default part is not modified
default:
$username = "restapi";
$password = "restapi";
$database = "pcss";
}
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
?>
I also saw this one: Access denied for user 'root@localhost' (using password:NO)
And tried changing the root's password, and I think this is the same thing with the alter thing. Just made me changed my configs (config.inc.php) again to access phpMyAdmin but still couldn't connect using PHP, still throwing the same access denied error.