Working With PHP & Databases
October 9, 2017 Comments 0 14 Views

Working With PHP & Databases

Working with PHP & Database require basic knowledge of below items :

  • Database Connection
  • Inserting Data
  • Reading Data
  • Updating Data
  • Deleting Data

Making Database Connection :

Using PHP you can make database connection by providing details like Host / Username / Password and make the database queries as per requirement. Once done you can close the mysql connection. Refer below code for reference.

Inserting Data :

Using below sample code you can insert any data to database table. Like below we have table name table where we are inserting 2 values in 2 columns.

Avoiding SQL Injection :

Any data you insert should be filter with mysqli_real_escape_string to avoid sql injection when hackers may try adding code to your database which might be harmful for your application.

Reading Data :

Using below sample code you can read data you inserted in database tables. Data can be fetched and displayed on web browsers for reports / profile etc.

Updating Data :

All data you added in database can be easily updated using below sample code. So if you need any change in data which is already inserted in database can be done using below code.

Deleting Data :

If there is any junk data or unwanted data you want to remove from the database then it can be easily deleted using below sample code. So you can search any value in column of table and delete the data from the table matching taht value.

Previous Magento 2 Admin Security Settings
Next Using Type Declarations in PHP 7

About author

Rio
Rio 34 posts

Expert web developer working in PHP, Wordpress, Joomla, Magento, Javascript etc.

You might also like

PHP 7 Using New Operators

PHP 7 also brings us some new operators. Let’s just cut the talk and directly check how PHP 7 Using New Operators. Spaceship Operator : The spaceship operator, or Combined Comparison

Using Type Declarations in PHP 7

PHP is considered to be a weak typed language. Using type declarations in PHP 7 simply means specifying which type of variable is being set instead of allowing PHP to

Error Handling in PHP 7

The next feature we going to cover are the changes to Error Handling. Handling fatal errors in the past has been next to impossible in PHP. A fatal error would

Creating HTML Form with PHP Server Side Validation.

This article will explain how you can create a HTML Form and do server side validation for the form. So the form which will display will be plain HTML and

Working with PHP Array – Indexed, Associative & Multi-Dimensional

PHP Array are variables which can hold more than one value at a time. For example if you want to store 1000 numbers then instead of defining 1000 variables its easy

Post data to third party site using PHP CURL

PHP supports CURL library which allows you to connect and communicate to many different types of servers with many different types of protocols and supports the http, https, ftp etc.

Difference between echo and print statements

In PHP there are two basic ways to get your output : echo and print statements. We will show the difference between echo and print statements with a working example.

ZIP Files & Folder using Simple PHP Code

Using PHP you can Zip Files and Folders with a simple php code, which will provide you with the functionality to create zip automatically without manual efforts. Simple PHP code to

PHP function to sort array alphabetically or numerically in ascending or descending order.

In this article we will walk through with example on how the PHP array sort functions works to sort the arrays key and values in alphabetically/numerically or ascending/descending order. Sort

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply

15 − 14 =