MySQL的預先處理技術使用測試

來源:互聯網
上載者:User

MySQL的預先處理技術使用測試

MySQL預先處理技術:

1.減輕伺服器壓力
2.防止sql注入,把傳遞過去的危險字元也只當做參數處理
3.將sql語句強制一分為二:第一部分為前面相同的命令和結構部分,第二部分為後面可變的資料部分

基本使用

prepare sql_1 from "select * from mass_list";
execute sql_1;
drop prepare sql_1;

  

傳參:

prepare sql_2 from "select * from mass_list where id=?";
set @id=1;
execute sql_2 using @id;

  

prepare sql_3 from "insert into mass_list (mass_name) values(?)";
set @name='zhang';
execute sql_3 using @name;

  

prepare sql_3 from "insert into mass_list (mass_name,user_email_id) values(?,?),(?,?)";
set @name='zhang';
set @id=1;
execute sql_3 using @name,@id,@name,@id;//參數按順序傳遞

本文永久更新連結地址:https://www.bkjia.com/Linux/2018-03/151363.htm

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.