php - Use a variable twice in prepared statement -


i'm beginning use prepared statements sql queries in php , in starting have come question.

i have function grabs user's id table @ login. want user able use either username or email address login.

so sql statement is:

select * `login` `username`=? or `emailaddress`=?

now when in query username , emailaddress same because can either or.

so when binding statements bind variable twice:

bind_param('ss', $user, $user); 

so value username , emailaddress needs same. want $user value of both placeholders.

my questions are: am doing correctly? is there more efficient way?

yes, have bind twice. if opposed reason, rephrase query as:

select * `login` l cross join       (select ? thename) const l.`username` = thename or `emailaddress` = thename; 

this using subquery name parameter can referred multiple times in query.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -