Could not connect to MySQL: Unknown database 'logindb'
Based on your error:-
It seems database with name logindb
does not exist. So check that once.
Also you used @
while creating connection, may be because of this you are not getting the exact errors which are happening in your code. Because @
is used for skipping errors.
So your code looks fine apart from above stated thing.May be it sound crazy too but check once below code:-
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
// Make the connection:
$dbcon = mysqli_connect('localhost','loger','loger','logindb') or die('Could not connect to MySQL: ' .mysqli_connect_error());
// Set the encoding...
mysqli_set_charset($dbcon, 'utf8');
?>
OR try once
$dbcon = mysqli_connect('localhost','loger','','logindb') or die('Could not connect to MySQL: ' .mysqli_connect_error());
Also check that password must be correct if you are providing. Because your errors in comment are stating like that you are using wrong password.
You can try to create a new user with new password and run the code.
After all these works if nothing happen then un-install and re-install the xampp
again. Thanks
MMG
Updated on June 04, 2022Comments
-
MMG almost 2 years
I am trying to connect to mysql database logindb using a separate mysqli_connect.php file. Here is my code:
<?php // This creates a connection to the logindb database and to MySQL, // It also sets the encoding. // Set the access details as constants: DEFINE('DB_USER', 'loger'); DEFINE('DB_PASSWORD', 'loger'); DEFINE('DB_HOST', 'localhost'); DEFINE('DB_NAME', 'logindb'); // Make the connection: $dbcon = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Could not connect to MySQL: ' . mysqli_connect_error()); // Set the encoding... mysqli_set_charset($dbcon, 'utf8'); ?>
I ma using XAAMP on Windows, but I get this error:
Could not connect to MySQL: Unknown database 'logindb'
Windows Firewall had blocked Apache HTTP and mysql in Inbound Rules, I allowed the connection but still same error. I am hell confused what is wrong?
edit
I think the problem is with Firewall as maybe sql is blocked! Anyway I uninstalled the XAMPP and reinstalled it and made logindb again and added the user with all the privileges and now it works. Thank You!
-
MMG about 8 yearsGot this warning on removing @ Warning: mysqli_connect()
-
MMG about 8 yearsI had no idea @ is used for skipping errors... thank you.. anyway i tried above code and got this Warning: mysqli_connect(): (HY000/1045): Access denied for user 'loger'@'localhost' (using password: YES) in C:\xampp\htdocs\login\abc.php on line 5 Could not connect to MySQL: Access denied for user 'loger'@'localhost' (using password: YES)
-
MMG about 8 yearsI think I better uninstall XAMPP and reinstall the damn thing and make completely new start...
-
MMG about 8 yearsLet me Do that...just a sec
-
MMG about 8 yearsWarning: mysqli_connect(): (HY000/1044): Access denied for user ''@'localhost' to database 'logindb' in C:\xampp\htdocs\login\abc.php on line 6 Could not connect to MySQL: Access denied for user ''@'localhost' to database 'logindb'
-
MMG about 8 yearsActually thank you...from the error of Unknown database 'logindb' it is now just having problem with user so let me make a new user and try....
-
MMG about 8 yearsThank You @Anant Problem Solved!