doujiao2000 2012-01-06 07:24
浏览 77
已采纳

PHP Mysql在where子句中使用MD5选择电子邮件

Consider this:

$email = 'c5dfd29d956b52c1ffa00ce4a06abad2'; // From the query string (MD5)

$result = mysql_query('SELECT * FROM ' . $table
          . ' WHERE MD5(email_address) = ' . $email);

$row = mysql_fetch_array($result);
echo $row['email_address'];

I want to get the value from the 'email_column' if the hashed emails are the same (From the database and from the query string using MD5). What is the correct way of doing this?

  • 写回答

1条回答 默认 最新

  • doru52911 2012-01-06 07:37
    关注

    First of all, you forgot to add quotes around $email in your query. Also, if you're taking it from the user, never ever forget to do mysql_real_escape_string before passing it to the DB.

    Also, since MySQL does not allow function indexes, you must understand that this query will require MySQL to read every row of the table and run MD5 on every email to check. You should rather store the hash in a separate field and have an index on it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了