![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Having trouble getting this to work ... running MySQL 5.0.51a on Ubuntu 8.04. I'm trying to create a stored procedure using phpMyAdmin. It compiles fine without these statements: PREPARE stmt FROM CONCAT( 'SET PASSWORD FOR `', vUsername, '`@`localhost` = PASSWORD(\'', vNewPwd, '\');' ); EXECUTE stmt; DEALLOCATE PREPARE stmt; What am I doing wrong? Do I have to declare "stmt" before using it as above? Thanks! |
#3
| |||
| |||
|
|
Looks like you have to do it this way: SET @a := CONCAT( 'SET PASSWORD FOR `', vUsername, '`@`localhost`=PASSWORD(\'', vNewPwd, '\');' ); PREPARE stmt FROM @a; EXECUTE stmt; DEALLOCATE PREPARE stmt; |
#4
| |||
| |||
|
|
Robert Hairgrove wrote: Looks like you have to do it this way: SET @a := CONCAT( 'SET PASSWORD FOR `', vUsername, '`@`localhost`=PASSWORD(\'', vNewPwd, '\');' ); PREPARE stmt FROM @a; EXECUTE stmt; DEALLOCATE PREPARE stmt; Still, there seems to be a problem using phpMyAdmin. I can call the procedure from the MySQL Query Browser OK, but I cannot fetch the return values in that environment. The new password is set correctly, however. When I call the procedure from phpMyAdmin, I get the "PROCEDURE: xxx.yyy can't return a result set in this context" error; this seems to me to be a bug in phpMyAdmin, however. The function definition looks like this: CREATE PROCEDURE `do_change_pwd`( IN vToken VARCHAR(40), IN vNewPwd VARCHAR(40), OUT vSuccess INTEGER, OUT vMsg VARCHAR(255) ) MODIFIES SQL DATA BEGIN -- -- -- END// If I replace everything between BEGIN and END with trivial code which merely sets the values of the OUT parameters, everything works as expected. I am calling the procedure like this: CALL schema.do_change_pwd('token','new_pwd', @x, @y); SELECT @x,@y; (although 'token' and 'new_pwd' obviously have different values...) Thanks for any suggestions! |
#5
| |||
| |||
|
|
I'm wondering why you even bother creating a stored proc just to change a password. |
#6
| |||
| |||
|
|
Jerry Stuckle wrote: I'm wondering why you even bother creating a stored proc just to change a password. It is for a web application written in PHP. There are several different users, all with very restricted access rights (i.e. only SELECT and EXECUTE on certain specific objects). The procedure is to enable someone to enter a new password if they have forgotten their old one, i.e. they can't log in to change their own password if they have forgotten it. They receive a confirmation e-mail with a link to the page which does the job. It's more secure that way than just e-mailing the users a new password in plain text. And if a user wants to change the password, they have to use the same procedure. |
#7
| |||
| |||
|
|
I still don't understand why you are creating a stored proc just to change a password. |

#8
| |||
| |||
|
|
Jerry Stuckle wrote: I still don't understand why you are creating a stored proc just to change a password. I suppose it could be done with PHP, but it seems just as simple to use a SP. The entire SP has only about 20 lines or so ... I'd probably have to write at least that many lines of code in PHP -- not counting the explanations given here... ![]() Can you (or anyone else) contribute something towards answering my original question now, please? |
#9
| |||
| |||
|
|
Jerry Stuckle wrote: I still don't understand why you are creating a stored proc just to change a password. I suppose it could be done with PHP, but it seems just as simple to use a SP. The entire SP has only about 20 lines or so ... I'd probably have to write at least that many lines of code in PHP -- not counting the explanations given here... ![]() Can you (or anyone else) contribute something towards answering my original question now, please? |
#10
| |||
| |||
|
|
Robert Hairgrove wrote: Can you (or anyone else) contribute something towards answering my original question now, please? I am. It's just not the answer you want. This is one line of code in PHP. You're making a mountain out of a molehill. Additionally, if this is a web application, there is no need to give each user a MySQL id. I use a single id for web access to MySQL, and a separate table for users and their privileges. |
![]() |
| Thread Tools | |
| Display Modes | |
| |