0

Everyone.

I have been trying to create user info saving process, and bumped into this issue. I wanted to use mysql function password() for password field, but seems no way to use MySQL function when to save data.

Is there any way to do this or simply it s impossible in CakePHP?

Thank you.

3

1 Answer 1

1

TLDR:

$this->data['MyModel']['password'] = 
    DboSource::expression('PASSWORD('.$password.')');

More Details:

I agree with the commenter that it's not ideal to do what you're asking, but if you really want to, you CAN run a regular MySQL query directly with the query() method. More info here:

http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-query

Example:

$this->Picture->query("SELECT * FROM pictures LIMIT 2;");

Or use the method mentioned above in the "TLDR" which allows you to use MySQL functions to process your data.

Different (but recommended) method:

Here is the documentation on how to hash your password the CakePHP way:

http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#hashing-passwords

Sign up to request clarification or add additional context in comments.

2 Comments

So... no way to use mysql function when to save data? I mean when to use $this->Model->save($save_data)
Glad it helped! Cleaned up a bit now that I know it's what you were looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.