MySQL:“`myTbl``foo` = foo”评估为true。我该如何预防呢?

时间:2011-08-29 03:10:25

标签: mysql configuration

说我有这样的存储过程:

BEGIN
    DECLARE user_id INT; 
    SET user_id = 1; 
    SELECT * FROM `users` WHERE `user_id` = user_id;
END

和这样的表:

users
=============================
user_id  |  user_displayname
-----------------------------
1        |  Joe
2        |  Steve
3        |  Brad

调用上面的存储过程为我提供:

1  |  Joe
2  |  Steve
3  |  Brad

我可以添加到my.cnf,告诉MySQL对标点符号非常严格吗?

我习惯于在java土地上并且能够做到:

int userId = 1;
if(aUserObject.userId == userId)
    //do something

1 个答案:

答案 0 :(得分:3)

怎么样:

SET @user_id := 1; 
SELECT * FROM `users` WHERE `user_id` = @user_id;