The difference between ${param} and #{param} in MySQL

The difference between ${param} and #{param} in MySQL

The parameter passed by ${param} will be treated as part of the SQL statement, such as passing the table name and field name

Example: (the value passed is id)

order by ${param}

The parsed SQL is:

order by id

#{parm} The data passed in is treated as a string, and double quotes are added to the automatically passed in data

Example: (the value passed is id)

select * from table where name = #{param}

The parsed SQL is:

select * from table where name = "id"

For security reasons, use # to pass parameters wherever possible, which can effectively prevent SQL injection attacks.

Introduction to SQL injection

I went directly to Baidu's example and it felt clear at a glance.

The SQL query code for login verification of a certain website is:

strSQL = "SELECT * FROM users WHERE (name = '" + userName + "') and (pw = '"+ passWord + "');"

Malicious entry
When userName = "1' OR '1'='1";與passWord = "1' OR '1'='1"; the original SQL string will be filled in as
strSQL = "SELECT * FROM users WHERE (name = '1' OR '1'='1') and (pw = '1' OR '1'='1'); "
That is, the SQL command actually executed will become the following strSQL = "SELECT * FROM users; "

This cleverly bypasses the verification during background account authentication, allowing users to log in to the website without an account or password. Therefore, SQL injection attacks are commonly known as hackers' fill-in-the-blank game.

This is the end of this article about the difference between ${param} and #{param} in MySQL. For more information about the difference between ${param} and #{param} in MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The difference between ## and $$ in dynamic SQL under Mybatis
  • A brief discussion on the difference between # and $ in mybatis and how to prevent sql injection

<<:  Solve the problem of black screen when starting VMware virtual machine

>>:  An article to help you thoroughly understand position calculation in js

Recommend

Detailed discussion of several methods for deduplicating JavaScript arrays

Table of contents 1. Set Deduplication 2. Double ...

How to optimize MySQL indexes

1. How MySQL uses indexes Indexes are used to qui...

Book page turning effects made with CSS3

Result:Implementation code: html <!-- Please h...

How to quickly delete all tables in MySQL without deleting the database

This article uses an example to describe how to q...

Steps to build the vite+vue3+element-plus project

Use vite to build a vue3 project You can quickly ...

Vue3 Vue Event Handling Guide

Table of contents 1. Basic event handling 2. Send...

How to install nginx in docker and configure access via https

1. Download the latest nginx docker image $ docke...

Solution to the conflict between nginx and backend port

question: When developing the Alice management sy...

Write a simple calculator using JavaScript

The effect is as follows:Reference Program: <!...

Detailed explanation of the principles of Vue's responsive system

Table of contents The basic principles of Vue'...

Detailed explanation of three ways to connect Docker containers to each other

There are three ways to interconnect and communic...

JavaScript to implement the back to top button

This article shares the specific code for JavaScr...

MySQL uses SQL statements to modify table names

In MySQL, you can use the SQL statement rename ta...

Use nginx to dynamically convert image sizes to generate thumbnails

The Nginx ngx_http_image_filter_module module (ng...