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

I am using IPBoard forums, and I decided to not use MD5, and use SHA512 instead. I am using notepad++, so I just renamed ALL md5( with hash('SHA512',.

And after installation, I get this SQL error.

Does that mean that SQL query doesn't support hash()? How can I fix it?

    $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();
  • You have 3 `(` opening brackets, but only 2 `)` closing brackets on your first hash() call... – Marc B Jul 18 '13 at 15:57
  • 1
    Please read [this](http://stackoverflow.com/a/4948393/727208), [this](http://stackoverflow.com/a/16896216/727208) and [this](http://stackoverflow.com/a/16044003/727208). – tereško Jul 19 '13 at 10:50

2 Answers2

1

The hash functions in MySQL are SHA1 and SHA2. You can refer the MySQL documentation for the proper syntax(https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html#function_sha2)

In your case the code should be

$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 is only available in MySQL versions 5.5.5 and above. Alternatively you can use the old SHA1 function but here you cannot control the bit length.

Suraj
  • 451
  • 7
  • 17
0

Change this:

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

to this:

SELECT hash('SHA512', CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ) ) as word_lookup
Maximus2012
  • 1,799
  • 2
  • 12
  • 15
  • you also need to change $this->DB->build( array( 'select' => "hash('SHA512', ( CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ) ) as word_lookup to $this->DB->build( array( 'select' => "hash('SHA512', CONCAT( lang_id, '-', word_app, '-', word_pack, '-', word_key ) ) as word_lookup – Maximus2012 Jul 18 '13 at 15:59