As we all know, MySQL user variables are specific to the client connection using them and exist only for the duration of that connection. When a connection ends, all its user variables are lost. Likewise, a prepared statement exists only during and is visible to the session that created it. When a session ends, all prepared statements for that session are discarded.
Another similarity is that prepared statements are also not case-sensitive like MySQL user variables. For example, both stmt11 and STMT11 are the same as shown in the following example -
mysql> Select * from student; +------+-------+ | Id | Name | +------+-------+ | 1 | Ram | | 2 | Shyam | | 3 | Rohan | +------+-------+ 3 rows in set (0.00 sec) mysql> SET @A = 'Sohan', @B = 3; Query OK, 0 rows affected (0.00 sec) mysql> EXECUTE Stmt11 USING @A, @B; Query OK, 1 row affected (0.12 sec) mysql> Select * from Student; +------+-------+ | Id | Name | +------+-------+ | 1 | Ram | | 2 | Shyam | | 3 | Sohan | +------+-------+ 3 rows in set (0.00 sec) mysql> SET @A = 'Gaurav', @B = 3; Query OK, 0 rows affected (0.00 sec) mysql> EXECUTE STMT11 USING @A, @B; Query OK, 1 row affected (0.04 sec) mysql> Select * from Student; +------+--------+ | Id | Name | +------+--------+ | 1 | Ram | | 2 | Shyam | | 3 | Gaurav | +------+--------+ 3 rows in set (0.00 sec)
In the above example, once we execute stmt11, they all work the same the next time we execute STMT11 because ready The statements are not case sensitive.
The above is the detailed content of What are the similarities between prepared statements and MySQL user variables?. For more information, please follow other related articles on the PHP Chinese website!