PHP/MySQL - Login system - Is it smart to SELECT the whole database? -


I'm in the process of creating a fairly easy login system, and I currently use the following code when a user logs Attempts to do this to determine whether there is an entry in that database that matches the user name in which the user tries to log in (later in the code, I check to match the password, etc. I am

Currently, I use SELECT to get the whole database in one variable ($ wholeUserDatabase), and then to determine whether 'Username' is repeated from field matches.

This works right now but there are still three users in my database when I issue the site to the public and (theoretically) get more users If so, does the pain slow down in this method of grabbing the entire database in a database?

  $ connection = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_password); Mysql_select_db ($ mysql_database, $ connection); // Take the entire user database, and store it in $ wholeUserDatabase $ WholeUserDatabase = mysql_query ("select from myTable") or die (mysql_error ()); $ BoolFoundUser = false; / * Dissolve once again for every entry in the database, by storing the current entry of the database into a variable $ current entry, which is everything related to a user. * / While ($ currentEntry = mysql_fetch_array ($ wholeUserDatabase)) / / Does the current entry "user name" field attempts to login from the user? * / If ($ currentEntry ['username'] == $ _POST ['username']) {/ * If this happens, break the loop so that $ currentEntry variable contains information for that user who logged in Trying to do that, later I'll need to check the password, etc. * / $ BoolFoundUser = true; break; }} Mysql_close ($ connection);   

Thanks for any help, I have to tell that I need to think about this part again. I hope this can be useful for other people.

I do not understand why you are doing this job. This loses the purpose of keeping the database in the first place. I mean, if you want to work in this way, then file I / O will be enough (i.e. to read from a plain text file).

What you want to do is SELECT * FROM myTable where the user name = $ username & amp; Amp; Password == $ password ...

This is better because (A) you can create indexes on the user who will be able to search / search the database faster, (b) less expensive than I / O and As processing perspective (A) you are not pushing all data (DB) to apply from DB, (b) mySQL does not need to be repeated on whole DB if its properly indexed (very fast) ) ...

Regards

Comments