Discussion: Is this the best way?
Afficher un message
Vieux 14/03/2008, 21h24   #9
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Is this the best way?

Jason Pruim wrote:
>
> On Mar 14, 2008, at 1:15 PM, Shawn McKenzie wrote:
>
>> Dan Joseph wrote:
>>>> I am attempting to add a little error checking for a very simple login
>>>> system. The info is stored in a MySQL database, and I am using mysqli
>>>> to connect to it. I have it working with the solution provided below,
>>>> but I am wondering if this is the right way to do it or if there is a
>>>> better way?
>>>>
>>>>
>>>>
>>> I don't see anything wrong with that method. One thing I would
>>> suggest is
>>> that you make username unique in your database if you want to avoid
>>> duplicate results. But your way of checking is just fine as it is.
>>>

>> To go along with this and making sure that usernames are unique, I would
>> LIMIT 1 on the query. With no LIMIT, if you have 300,000 users, then
>> the query will not stop if it matches the first user, it searches all
>> 300,000. With LIMIT 1 it will stop on the first match.

>
> Hi Shawn,
>
> I do have a LIMIT 0,1 that didn't make it into the actual copy/paste.
> Thanks though for the tip!
>


If this is the case, then you will never have a situation where your result set
will be larger then 1. It will be either 1 or 0 (zero).

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
  Réponse avec citation
 
Page generated in 0,05482 seconds with 9 queries