PHP MySQLi Utilization with Our Application

MySqli is updated version and gives an object oriented and the number of enhancement over the regular MySql extension. These extensions are much faster, efficient and totally secure against SQL injections. In this post, we will understate the basic usage of MySqli, such as connect, insert, select, update and delete operations with many options with MySQL details.

Connect to Database

We can able to make a connection with Database using MySqli in two methods. It’s procedural and object-oriented method. For the secure purpose we preferred object-oriented method and also it is faster and efficient. The procedural method is similar to Mysql concept.

Fetch the record details from Database

We want to show the details from Database means first execute the select query with the help of connection object. Select records with many methods like fetch_assoc(), fetch_array() and fetch_object().

fetch_assoc() : Following code, use to fetch the records with an associative array. The fetching database result array has a column name as key and value for the corresponding column.

fetch_array() : This method returns an array of both MySqli fetch_row() and MySqli fetch_assoc() joined mutually, it is an advance version of the mysqli_fetch_row() method. It will handle even number and string can be used as a key to access the result data.

fetch_object() : To get the database result set as an objects, just use MySqli fetch_object(). Here the data will be display by the object key. Object key as the column name in a database table.

Get the Total records count with fetching the help of select query result. fetch_row() method is used to get the count for result set data.

Insert one record set using MySqli:

Below code is use to save the particular details into a database using connection object in MySqli.

Update the existing record details:

Below code is use to update or change the existing details into new details with the specific condition or key sets.

Remove or delete existing record details:

Below code is use to remove or delete particular records from a database.

 

Learn Infinity

Learn Infinity is the most famous Programming & Web Development blog. Our principal is to provide the best online tutorial on web development. We execute the best tutorials for web experts this will help developers, programmers, freelancers and proving free resource you can download or preview the tutorials.

Leave a Reply

Your email address will not be published.

Back to top