postheadericon PHP-Delete Record using prepared statement in PDO

Part-7: Delete Record using prepared statement in PDO.



In the last and part number seven, explain how to delete record using prepared statement. To keep delete operation simple I have not added any prompting for the confirmation of record deletion from user side.  This can be done by little bit JavaScript coding.

To delete a record first we have to select that which record we want to delete from MySQL table. Like our previous update operation we again utilize the result of search or display operation where a like delete is there to do the delete operation. When user click on that delete link the id of record is pass as a GET request to delete.php file where the actual delete statement execute of database and delete operation performed using prepared statement.

postheadericon PHP - Update Record using prepared statement in PDO

Part-6: Update Record using prepared statement in PDO


I part six, we do the update operation. To do the update we need to select a record which user want to update. From search or display operation that we discuss in previous part user click on edit link and select record for edit. When user select or click on edit link it will pass the id field in GET request to our edit.php file. With the help of record id we retrieve the entire record from table and fill it in to a HTML form where user can do the update operation. After updating information in HTML form user submit the update value by Update button. It pass all the information to our update.php file where the actual update SQL query execute on MySQL table and update the record using prepared statement of PDO. 

postheadericon PHP - Search records using AJAX and PDO



Part-5: Search records using AJAX and PDO in PHP



In part five, we do the search operation on our MySQL table. We use prepared statement to execute our query using PHP-PDO object. In SQL query we use like operator so it match record like the input we get from search.html file. To do the search object we use the AJAX technology to pass the request to search.php file. The file search.php is exactly similar to display.php file, just a where condition is added to do the search operation.  If we do the smart work then one file display.php or search.php is enough to do both operation just an if condition is required that check the request parameter whether search criteria is provided or not? To keep it simple I have use to separate file that would be helpful to beginners.

postheadericon Part-4: Display Records using prepared statement



Part-4: Display Records using prepared statement.



In part four, we concentrate on fetching record from database using prepared statement. We use select SQL statement to retrieve all record from table. After executing our query using PDO object we check whether it return the rows or not. If it does not return records then “No record found.” Message will be shown otherwise record will be display in HTML table. Last two column have link for Edit and Update record. When user click on it, it pass id to edit or delete page using default GET method. 


postheadericon PHP insert update, delete using PDO part-3


Part-3: Insert record using prepared statement in PDO.


In part three, I am creating two file one is the HTML file (insert.html) to define form to get the information and second one (insert.php) is the code behind file to retrieve the values from HTML and insert those values in database using prepared statement with the help of PDO.

postheadericon PHP insert update, delete using PDO part-2



Part-2: Create a MySQL Database and a table using PDO.


In part two, I am going to create a setupdb.php file where I do following task.

1. Database connection in PHP and MySQL using PDO,
2. Create database in MySQL which name we define in config.php
3. Create table in MySQL using PDO
4. Insert sample records using prepared statements.

postheadericon PHP insert update, delete using PDO part-1

Part-1: Configure and Setup the MySQL database connection using PDO.

In this example, I am going to create separate files for each database operations which require to do database connection. In part one, I define few constant that is going to use throw-out the application in config.php and conn.php where I define the $conn connection object.

config.php


<?php
define("servername","localhost");
define("username","root");
define("password","admin");
define("mydb","bsrdb");
?>

postheadericon PHP PDO : insert, update delete example for beginners




Creating a web application using PHP (Hyper Text Preprocessor) and PDO (PHP Data Object). Here in this article I am exploring the latest feature of PHP to do better deal with databases. Yes, it’s PDO. After the many feature of MySQL function are improved or depreciated the MySQLi (MySQL improved) introduce. Still MySQLi is doing well but problem is you can connect to only one database using it that is MySQL. To improvise the better database connectivity option for most popular web server side scripting language PHP. PHP introduce PHP data object (PDO). So, Question is -, 

What is this PDO?

PDO is PHP data object which provide the data access layer. PDO have uniform and most powerful API methods to access multiple web databases using PHP.

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.