What is parameterized query?

后端 未结 4 2183
攒了一身酷
攒了一身酷 2020-11-21 11:12

What is a parameterized query, and what would an example of such a query be in PHP and MySQL?

4条回答
  •  眼角桃花
    2020-11-21 11:56

    This statement is one of features of the database system in which same SQL statement executes repeatedly with high efficiency. The prepared statements are one kind of the Template and used by application with different parameters.Reference Article

    Database System can execute the same SQL statement without doing the parsing, compiling and optimizing again and again for the same kind of SQL Statement.

    You can write or create prepared statement in MySQL but this is not an efficient way because the binary protocol through a prepared statement API is better.

    But still you can write and even this doesn’t require any other programming you can directly write in SQL. You can use a prepared statement for MySQL Client program.You can also use a prepared statement in a stored procedure for the dynamic SQL approach.

    Create prepared statement in MySQL: reference is taken from this article

    PREPARE TestStmt FROM 
    'SELECT * FROM Test 
    WHERE TestNumber=?';
    

    You can use PHP code to manage prepared statement through its API or manage at the level of JDBC.

提交回复
热议问题