Home > Database > Mysql Tutorial > What are the similarities between prepared statements and MySQL user variables?

What are the similarities between prepared statements and MySQL user variables?

WBOY
Release: 2023-08-24 19:57:06
forward
944 people have browsed it

准备好的语句和 MySQL 用户变量有什么相似之处?

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template