Posts

Webservices in PHP (How to create user registration/signup Webservice)

Image
  What is Webservices? Webservices are used to allow users to access data from different sources like the Android app, IOS app, website etc from a centralized database. We can create a web service through two methods : SOAP (Simple Object Access Protocol) REST (Representational State Transfer) SOAP (Simple Object Access Protocol) SOAP : Simple Object Access Protocol. SOAP is easy to read because SOAP based on XML. SOAP is the XML based format  for sending and receiving data. REST (Representational State Transfer) REST : Representational State Transfer. It is an architectural style that run over HTTP. REST webservices generate status code response in JSON & XML. REST support all HTTP methods GET, POST, PUT & DELETE. GET :  Retrieve particular resources by an id POST :   Create a new resource. PUT :  Update a  particular resource by an id. DELETE :  Remove a particular  resource. Click : https://phpgurukul.com/webservice...

CRUD operation using PHP and MySQLi | PHP Gurukul

Image
 In this tutorial, we will learn how to create CRUD operation using PHP and MySQLi . CRUD Stands for create, read, update and delete record in the database. Files includes in this tutorials phpcrud.sql:  Contain the database table structure. dbconnection.php:  Used for database connection. index.php : Used to fetch the record from database. read.php:  Used to fetch the record of particular user. edit.php:  Used to edit the record. insert.php:  Used to insert the new record. Step 1– Create a database Open browser type http://localhost/phpmyadmin, create a database named ‘phpcrud’. After creating database run the SQL script or import the SQL file. MySQL Table tblusers structure CREATE TABLE `tblusers` ( `ID` int(10) NOT NULL, `FirstName` varchar(200) DEFAULT NULL, `LastName` varchar(200) DEFAULT NULL, `MobileNumber` bigint(10) DEFAULT NULL, `Email` varchar(200) DEFAULT NULL, `Address` mediumtext DEFAULT NULL, `CreationDate` timestamp NOT NULL D...

Interfaces – the next level of abstraction

Image
  Interfaces resemble  abstract classes  in that they include abstract methods that the programmer must define in the classes that inherit from the interface. In this way, interfaces contribute to code organization because they commit the child classes to the methods that they should implement. The use of interfaces become very helpful when we work in a team of programmers and want to ensure that all the programmers write the methods that they should work on, or even in the case of a single programmer that wants to commit himself to write certain methods in the child classes. An interface commits its child classes to abstract methods that they should implement. How to declare and implement an interface? We declare an interface with the interface keyword and, the class that inherits from an interface with the implements keyword. Let’s see the general case:   1 2 3 4 5 6 7 interface interfaceName { // Abstract methods } class Child implements interfaceName { // D...

Polymorphism in PHP

Image
  In this tutorial, we are going to learn a naming convention that can help us write code which is much more coherent and easy to use. According to the Polymorphism (Greek for “many forms”) principle, methods in different classes that do similar things should have the same name. According to the Polymorphism principle, methods in different classes that do similar things should have the same name. Click : https://phpgurukul.com/polymorphism-in-php/ A prime example is of classes that represent geometric shapes (such as rectangles, circles and octagons) that are different from each other in the number of ribs and in the formula that calculates their area, but they all have in common an area that needs to be calculated. In such case, the polymorphism principle says that all the methods that calculate the area (and it doesn’t matter for which shape or class) should have the same name. For example, we can write in each class that represents a shape a calcArea() method that calculates the...

Static methods and properties | PHP Gurukul

Image
  We can access static methods and properties without the need to first create an object, but their use should be limited. We have already learned about the three access modifiers called  public , protected and  private . This chapter is devoted to the fourth modifier, static, that allows access to classes’ properties and methods without the need to create objects out of the classes.  How to define methods and properties as static?  In order to define methods and properties as static, we use the reserved keyword static. In the following example, the class Utilis has a static public property with the name of $numCars, and so the property’s name is preceded by both the static as well as the public keywords. Click : https://phpgurukul.com/static-methods-and-properties-2/   1 2 3 4 5 class Utilis { // Static methods and properties // are defined with the static keyword static public $ numCars = 0 ; } How to approach static methods and properties? In order...

What are exceptions and how to handle them?

Image
 Exception handling is an elegant way to handle errors which are beyond the program’s scope. Click : https://phpgurukul.com/what-are-exceptions-and-how-to-handle-them/ In this tutorial, we are going to learn how and when to use exception handling and, even more important, when not to use it. In order to explain the need for exception handling, we will try to see what happens when a program is fed with faulty data. In our example, we will develop the class FuelEconomy that calculates with the method calculate() the fuel efficiency of cars by dividing the distance traveled by the gas consumption. class FuelEconomy { // Calculate the fuel efficiency public function calculate ( $ distance , $ gas ) { return $ distance / $ gas ; } } We will feed the class with the nested array $dataFromCars, in which each nested array has two values: the first value is for the distance traveled and the second value is for the gas consumption. While the first and last nested arrays contain legitima...

Learn How to Develop Object Oriented Programming Concepts in PHP

Image
  Learn How to Develop Object Oriented Programming Concepts in PHP Centered around the concept of manipulating objects by identification, also known as modeling, is what OOP is all about. The identification and relation of objects to each other is what the programmer attempts. This novel concept of programming is a lot different from logic based programming. Let us dive through the codes to get a better understanding of OOP and how the concepts can be used in PHP. Classification of data OOP defines classes of data and sub classes.  This reduces the time required for development, in addition to helping in accurate coding. By virtue of the extensive analysis of the data, known as inheritance this characteristic of OOP sets it apart. OOP prevents data corruption.  As a result of the classification, the codes will never be able to access data that is unconnected. Known as data hiding, this typical characteristic of OOP lends it greater security. OOP permits programmers to cre...