From the course: PHP with MySQL Essential Training: 1 The Basics

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Prepared statements

Prepared statements

- [Instructor] Prepared statements are a feature of MySQL and many other databases. They are an advanced concept, but I think it's worthwhile to introduce them so that you can understand what they are. The general idea is that you give MySQL a template for a query that you want to run, and you indicate places where you can fill in the blanks later. You can see those here are indicated by the question marks. Then when we want to run the query, we call up our template. We fill in the blanks and we tell MySQL to run it. Why do it this way? Well, it allows us to prepare the statement once and then reuse it again in the future. And that can make things faster. When any query runs, the database has to parse it and then develop a plan for running it. With prepared statements, The database does this work one time, and then you can reuse that work for future queries, where only the variables are changing. That can be faster, especially if you're doing complex queries or repeating the query…

Contents