Web Development -

CRUD Operation in PHP-PDO

Today i am giving you toturial on PDO-PHP .Here i will creat full CRUD system in PDO using PHP. So below is your connection in PDO so see carefully it looks tought but dont worry it is very easy compare to Mysqli. I didnt give file name here it is upto you what name you want to give. Just remember the syntax ”bindparam” is used for bind your data and colon ( : ) is uesd for SQL INJECTION prevention

Always use try & catch block for pdo connection and if you dont use try-catch then you cant cathc your error . For source code comment your mail

I have used PHP include_once function to connect database connection to all files but you can write DB connection in each file but good practise is use connection file separately and connect it with help of require_once or inlcude_once.

Now this is screen short of your add form page

Now this is your form code

This code will use for insert your data in table using PDO Method

Now i am putting code of index file ,Below is your index.php file or you can say main page of your small project

We can use query or execute statement method in PDO but exceute is more safer than query against Sql Injection

query runs a standard SQL statement and requires you to properly escape all data to avoid SQL Injections and other issues.

execute runs a prepared statement which allows you to bind parameters to avoid the need to escape or quote the parameters. execute will also perform better if you are repeating a query multiple times. Example of prepared statements:

and

So i have given you two examples how to write query and excecute method in PDO

This is screenshort of your index.php

Now i will put code of edit.php

Now this is final code block which your delete.php

This way you can do CRUD Operation in PHP-PDO.

Check these tutorials in php

Get the largest number in php

Its very simple to get the highest number in PHP

Sorting an array in PHP

Sorting is a very important topic in PHP and you can achieve the sorting in PHP very easily.

Output

Your unsorted array : Array ( [0] => 2 [1] => 4 [2] => 8 [3] => 5 [4] => 1 [5] => 7 [6] => 6 [7] => 9 [8] => 10 [9] => 3 )
Your sorted Array : Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 )

What is aggregate and Scalar Functions

What are Aggregate and Scalar capacities?

A total capacity performs activities on an accumulation of qualities to restore a solitary scalar worth. Total capacities are regularly utilized with the GROUP BY and HAVING provisions of the SELECT articulation. Following are the broadly utilized SQL total capacities:

AVG() – Calculates the mean of an accumulation of qualities.

Check() – Counts the absolute number of records in a particular table or view.

MIN() – Calculates the base of an accumulation of qualities.

MAX() – Calculates the limit of an accumulation of qualities.

Entirety() – Calculates the whole of an accumulation of qualities.

FIRST() – Fetches the main component in an accumulation of qualities.

LAST() – Fetches the last component in a gathering of qualities.

Note: All total capacities portrayed above disregard NULL qualities aside from the COUNT work.

A scalar capacity restores a solitary worth dependent on the information esteem. Following are the generally utilized SQL scalar capacities:

LEN() – Calculates the all out length of the given field (segment).

UCASE() – Converts an accumulation of string esteems to capitalized characters.

LCASE() – Converts a gathering of string esteems to lowercase characters.

MID() – Extracts substrings from a gathering of string esteems in a table.

CONCAT() – Concatenates at least two strings.

RAND() – Generates an irregular accumulation of quantities of given length.

ROUND() – Calculates the round off whole number an incentive for a numeric field (or decimal point esteems).

Presently() – Returns the present information and time.

Configuration() – Sets the organization to show an accumulation of qualities.

What is Primary Key in SQL

What is a Primary Key?


The PRIMARY KEY constraint uniquely identifies each row in a table. It must contain UNIQUE values and has an implicit NOT NULL constraint.
A table in SQL is strictly restricted to have one and only one primary key, which is comprised of single or multiple fields (columns).

The PRIMARY KEY imperative interestingly recognizes each column in a table. It must contain UNIQUE qualities and has a certain NOT NULL limitation.

A table in SQL is carefully limited to have one and just a single essential key, which is involved single or various fields (segments).

CREATE TABLE Employee(
Emp_ID INT NOT NULL
First_Name VARCHAR(25)
PRIMARY KEY ( Emp_ID )
);

CREATE TABLE Employee (
Emp_ID INT NOT NULL
F_Name VARCHAR(255)
Father_Name VARCHAR(55) NOT NULL,
CONSTRAINT PK_employee
PRIMARY KEY ( Emp_ID , F_Name)
);

ALTER TABLE employee
ADD PRIMARY KEY (emp_ID);

ALTER TABLE Employee;

What is Sql – Constraints

What is Sql – Constraints

Constraints are utilized to indicate the principles concerning information in the table. It tends to be connected for single or different fields in a SQL table during the formation of a table or in the wake of making utilizing the ALTER TABLE direction. The imperatives are:

NOT NULL – Not Null Value should be Inserted in the table.
CHECK – Verifies that all values in a field satisfy the given condition.
DEFAULT – Automatically assigns a default value if no value has been specified for the field.
UNIQUE – Ensures unique values to be inserted into the field.
INDEX – Indexes a field providing faster retrieval of Data.
PRIMARY KEY – Column Name uniquely identifies each record in a table.
FOREIGN KEY – Ensures referential integrity for a record in another table.

Search Filter in PHP MYSQL

CRUD Operation with Search Filter Feature

I will show you a full code of CRUD operation with a search filter option. I have used Core PHP for backend and Javascript, CSS and Html for Front-end. I didn’t have used ajax call for sending and receiving requests.

First see the database of this project

id , city and country only 3 coloumns . Now connection code

conn.php

Project Screen Short –

I have divided code into 10 pages Header , footer and source code .

Now I will start from the add.php page it has designing and coding part as well.

I have called the connection of database using require() function of PHP. You can use either include() or include_once() or require() according to your requirements.I am using CDN link to enable Bootstrap functionalities into your code.

Now we will see an index.php page which is your the main page and you have seen this page in the first screen short.

index.php

Now we will see header.php , footer.php , edit.php and delete.php .

header.php

The header page has all cdn links of Boostrap and Jquery.

footer.php

Now we will see update and delete page .

update.php

Now will see delete.php page

delete.php

Now lets see search filter option.

search_action.php

Finally will see style.css .

style.css

How to color background of last inserted row in PHP

Without last_insert_id

I have colored background of last inserted row without using last_insert_id. You can do this by using LIMIT and ORDER BY of MySQL.

Php insert id , php last_insert_id

Database Structure :

id , name , address , gender , designation ,age

Now lets start with our code ,First make this databse table in your database.

In this way you can color the background of last inserted row in php

See our more articles on PHP and JAVASCRIPT

How to make sales receipt in PHP

Pagination in php

Show data from using Drop Down list in PHP

How to show data from Database using drop-down PHP

We can show database value in a table using the dropdown list. Below is a database structure. You can add more data to the database.

Database Structure

idnameaddressgenderdesignation
1RobertLondonMaleProfessor
2DianaMumbaiFemaleEngineer

Now we will see code for dropdown list

This is way we can show data in a table using drop down.

OutPut of the code :

See our more articles on PHP, JAVASCRIPT and JQUERY

How to make sales receipt in PHP

Sales print in php

It’s very easy to make a sale receipt like Amazon in PHP. I am only fetching data from the database so I have used myself. The database Columns name would be – id, name, price, qty (int, varchar, int, int ).

I have multiplied Price into Quantity to get Total Price. Price * Quantity = Total Price.

See More tutorials on PHP and JAVASCRIPT .

Shopping cart in PHP

Shopping cart in PHP

How to make Shopping cart in Core php

I didn’t have used any PHP framework. This shopping cart in core PHP and it is only for beginners. You will see Add to cart, Add to a product, delete a product, preview product, log in, and log-out. I have written a design code on a different page and business logic code on a different page.

Technolgy Used : PHP ,MY-SQL , HTML ,CSS ,BOOTSTRAP ,JAVASCRIPT & JQUERY.

If you run this project in your browser you will see this output. For source code please leave your mail in the comment box.

This is your project structure in your folder. As I said Business logic and design code both have written on different pages.

Now start with a database this is the database design. There are two tables and a total of 9 columns. Save table is used for Registration and Login.

Now I will show you the complete code of connection as know that without connection can’t complete this project.

Save this code as connection.php

Now we will see Sign up page code and login page code. Now see registration.php This page only has designing part and business logic will be on a different page with the name registration_action.php

registration.php

Now you will see business logic of registration page.

registration_action.php


The extract() Function is an inbuilt function in PHP. The extract() function does array to variable conversion.

Now we will see login page but first, we will see design page of login then business logic.

index.php (Design page of Login Form)

Now we will see business logic of Login form index login_action.php

This is our logout page logout.php

error_reporting(0) is used to avoid warning and notice. Now the next step is to add header and footer page. I didn’t add any menu in the header but there is a menu in the footer but the footer menu is empty.

header.php

footer.php

Now we will see the code of home page which showing four data in the front end. You can add more products but I am showing just four product on each row.

main.php

Now we will see how to add product in main page . There are total 8 coulumns.

This is designing page of add_product page add_product.php

Now see business logic of add_product page product_action.php

How to see product in diffrent page or on model box . view_detail.php

Now, this is our last code of the project, how to remove a product from the main page. empty_cart.php

If you want source code of this project please drop your mail in the comment box.