检查用户名是否存在 [英] Check If Username Exists

查看:98
本文介绍了检查用户名是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查用户名是否存在于MySQL表中的最佳方法是什么?

Whats the best way to check if a username exists in a MySQL table?

推荐答案

SELECT COUNT(*) as count FROM users WHERE username='whatever'

读出第一条结果行-如果计数"列> 0,则表示用户名存在.

read out the first result row - if the 'count' column is > 0 then the username exists.

或者,在php中,您可以使用:

Alternatively, in php, you could use:

SELECT * FROM users WHERE username='whatever'

然后使用mysql_num_rows(或等效的版本).

Then use mysql_num_rows (or the equivalent).

这篇关于检查用户名是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆