1

im trying to create login system for my school project, but I run into a problem. When I'm trying to connect to database it always throw error:

Warning: mysqli::__construct(): (HY000/1049): Unknown database 'userverification'

It will pass only when I use databases which were created with installation of phpMyAdmin.

Code Im using for connecting is:

<?php

        define('DB_HOST', 'localhost');
        define('DB_USER', 'root');
        define('DB_PASS', '');
        define('DB_NAME', 'userverification');


        $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

        if ($conn->connect_error) {
             die('Database error: . $conn->connect_error');
        }
?>
ChessMan
  • 11
  • 2
  • then it means there is no database having those parameters. – Rotimi Mar 25 '20 at 12:34
  • 1
    This error tells you that your *DBMS* has no Database named *userverification*. The DB doesn't have to be created explicitly through phpmyadmin, but it must be somehow created. It seems to me that you are asking following question _Why can't i connect to a non existing database_ which sounds silly, you can't because the Database does not exist. – Eugene Anisiutkin Mar 25 '20 at 12:36
  • Does `userverification` is database name, not a table name in some database? check that `SHOW DATABASES` lists it (execute in phpMyAdmin or in console client)... – Akina Mar 25 '20 at 12:44
  • @EugeneAnisiutkin I thought that I can create database in phpmyadmin and than write code and it will connect. This is what I did, I created database in phpmyadmin. I dont know what Im doing wrong then. – ChessMan Mar 25 '20 at 12:47
  • @Akina It is database name. I did that command and `userverification` is in the list. – ChessMan Mar 25 '20 at 12:50
  • This question has tons of answers in this site, This is one of your answer I think https://stackoverflow.com/a/60655066/12232340 or this one https://stackoverflow.com/a/59813485/12232340 –  Mar 25 '20 at 12:52
  • @Dlk Oh my god, thanks a lot for these answers. I wasnt able to to find the right words to search for these. It works now. Thanks a lot. – ChessMan Mar 25 '20 at 13:15
  • @ChessMan Glad I helped! You could upvote that answers :) –  Mar 25 '20 at 13:16

0 Answers0