2
mySQL query error: SELECT hash('SHA512', ( CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ) ) as word_lookup, word_id, hash('SHA512', word_default) as word_default, word_default_version FROM forum_core_sys_lang_words WHERE word_app='core' AND lang_id IN(1)

SQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('SHA512', ( CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ) ) a' at line 1
SQL error code: 1064
Date: Thursday 18th July 2013 03:34:35 PM

我正在使用 IPBoard 论坛,我决定不使用 MD5,而是使用 SHA512。我正在使用记事本++,所以我只是将 ALL 重命名md5(hash('SHA512',.

安装后,我收到此 SQL 错误。

这是否意味着 SQL 查询不支持 hash()?我该如何解决?

    $this->DB->build( array( 'select'   => "hash('SHA512', ( CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ) ) as word_lookup, word_id, hash('SHA512', word_default) as word_default, word_default_version",
                             'from'     => 'core_sys_lang_words',
                             'where'    => "word_app='{$app_override}' AND lang_id IN(" . implode( ",", $lang_ids ) . ")" ) );
    $this->DB->execute();
4

2 回答 2

1

MySQL 中的哈希函数是 SHA1 和 SHA2。您可以参考 MySQL 文档以了解正确的语法(https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html#function_sha2

在您的情况下,代码应该是

$this->DB->build( array(
    'select'   => "SHA2(CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ), 512) AS word_lookup, word_id, SHA2(word_default, 512) AS word_default, word_default_version",
    'from'     => 'core_sys_lang_words',
    'where'    => "word_app='{$app_override}' AND lang_id IN(" . implode( ",", $lang_ids ) . ")"
));

SHA2 仅在 MySQL 5.5.5 及更高版本中可用。或者,您可以使用旧的 SHA1 函数,但在这里您无法控制位长。

于 2013-07-18T16:00:04.390 回答
0

改变这个:

SELECT hash('SHA512', ( CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ) ) as word_lookup

对此:

SELECT hash('SHA512', CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ) ) as word_lookup
于 2013-07-18T15:40:51.880 回答