PHP mysqli prepared statement insert example

MySQLi is the improved version of MySQL extension and it has more feature which is included in PHP Version 5.

The advantage using MySQLi is:

1. Prevent SQL Injection
2. Able to Prepare statement and bind params.
3. OOPS Interface and more.

In this tutorial you can learn how to insert values into the table using mysqli prepared statement.

First create a table, use the below SQL query:

Totally four fields in the above table with three different data types,

1. int
2. varchar
3. double

2. Here is the PHP script:

The code is self explanatory, just read the comments.

If you already worked in other technologies such as Java or .Net you would know about prepared statement. But PHP developer not used this even though introduced long time back.

These are the steps you have follow:

1. prepare statement (?,?)
2. bind params with the proper data type

3. execute


Add a Comment

Your email address will not be published. Required fields are marked *