vit*_*tto 2 php mysql md5 compare
我正在尝试从我的php页面跨md5函数验证mysql上的一对数据列.
我用php md5函数加密了字符串"helloworld",并试图将它与MYSQL MD5函数进行比较,但它不起作用.
我这样做是因为在数据库中有一对字符串"hello"和"world"需要与我的php字符串进行比较,所以:
<?php
$str_a = "hello";
$str_b = "world";
$str_encrypted = md5 ($str_a.$str_b);
// note "first_col" is "hello" and "second_col" is "world"
$sql = "UPDATE `my_table` SET `checked_col` = '1' WHERE MD5(CONCAT(first_col,second_col)) = '$str_encrypted' LIMIT 1;";
$res = mysql_query ($sql) or die (mysql_error());
($res) ? print "true" : print "false";
?>
Run Code Online (Sandbox Code Playgroud)
这段代码返回false,并且数据库没有UPDATE列检查列,但没有返回mysql_error问题.
来自php 的md5可以从MYSQL 生成不同的MD5吗?
朋友写的类似代码在同一台服务器上工作,但我没有多少经验可以看出差异在哪里
谁能解释我错在哪里?
谢谢!
我不会混用和匹配MD5功能.可能更容易考虑任何md5功能的单行道.所以修改它是:
$str_concat = $str_a.$str_b;
// note "first_col" is "hello" and "second_col" is "world"
$sql = "UPDATE `my_table` SET `checked_col` = '1' WHERE
MD5(CONCAT(first_col,second_col)) = MD5('$str_concat') LIMIT 1;";
Run Code Online (Sandbox Code Playgroud)
或者只是简单地使sql匹配.
// Skip the php concatenation.
// note "first_col" is "hello" and "second_col" is "world"
$sql = "UPDATE `my_table` SET `checked_col` = '1' WHERE
MD5(CONCAT(first_col,second_col)) = MD5(CONCAT('$str_a','$str_b')) LIMIT 1;";
Run Code Online (Sandbox Code Playgroud)