R
R
Ruslan2014-08-10 17:55:54
MySQL
Ruslan, 2014-08-10 17:55:54

MySQL - Why does it return NULL due to a MySQL function?

There is a request:

SELECT `password`,UPPER(md5(GROUP_CONCAT(CONCAT_WS(':',`pl_id`,`password`)))) FROM `admins` WHERE name = '%s' AND pl_id = '%d'

If nothing is found then NULL is returned, how to use IS NOT NULL in this situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
svd71, 2014-08-10
@svd71

If nothing is found, then the returned cursor will contain 0 entries, not NULL.
Although any operations with a NULL value return a NULL value.
PS: It's a bit unreasonable to store passwords in the database in plaintext. Any hack leads to the direct disclosure of passwords. It is much safer to store only md5 calculated along with the salt. Even the known value of the salt makes it difficult to directly access the data.

I
Immortal_pony, 2014-08-11
@Immortal_pony

SELECT 
    CASE WHEN COUNT(`password`) = 0 THEN
      'There is no results'
    ELSE UPPER(md5(GROUP_CONCAT(CONCAT_WS(':',`pl_id`,`password`)))) END AS
  'str'
FROM portal.`channels` c
WHERE name = '%s' 
AND pl_id = '%d'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question