Home > Database > Mysql Tutorial > body text

How to update a table using prepared statements?

王林
Release: 2023-08-28 21:53:02
forward
1073 people have browsed it

How to update a table using prepared statements?

It can be understood through the following example, in which we have updated the table named "Student" using prepared statements, which contains the following data-

mysql> Select * from Student;
+------+-------+
| Id   | Name  |
+------+-------+
| 1    | Ram   |
| 2    | Shyam |
| 3    | Mohan |
+------+-------+
3 rows in set (0.00 sec)

mysql> PREPARE stmt11 FROM 'UPDATE Student SET Name = ? WHERE Id = ?';
Query OK, 0 rows affected (0.03 sec)
Statement prepared

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.05 sec)

mysql> Select * from student;
+------+-------+
| Id   | Name  |
+------+-------+
| 1    | Ram   |
| 2    | Shyam |
| 3    | Sohan |
+------+-------+
3 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How to update a table using prepared statements?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!