Core & Adv PHP Meterial
Core & Adv PHP Meterial
Charmi : B C
SHRUSTI C C
Vaibhavi B A
Dixit A A
Divya B B
Ravi B A
Hitanshi
1) What is PHP ?
2) PHP features ?
● Simple
● Interpreted
● Faster
● Open Source
● Platform Independent
● Case Sensitive
● Speed Comparison of ASP PHP JSP
● Simplicity
● More frameworks & CMS
● PHP 7 is much faster than the previous popular stable release (PHP 5.6)
● PHP 7 has improved Error Handling
● PHP 7 supports stricter Type Declarations for function arguments
● PHP 7 supports new operators (like the spaceship operator: <=>)
● For project development rules & regulation need to be followed for best quality output at
defined time limit
● Rules are Software Development Life Cycle – SDLC
● It‘s part of software engineering
● Six rules to be followed…
1. Requirement Gathering
3. Designing
4. Implementation (Coding)
5. Testing
6. Maintenance
Rdbms
RDBMS stands for Relational Database Management Systems..
All modern database management systems like SQL, MS SQL Server, IBM DB2, ORACLE,
My-SQL and Microsoft Access are based on RDBMS.
It is called Relational Database Management System (RDBMS) because it is based on
relational model introduced by E.F. Codd.
4 Types
1 foregn key
2 foregn key
alter:
ALTER TABLE `customer` add `gender` varchar(100) AFTER `pro_name`;
ALTER TABLE `customer` CHANGE `mob` `mobile` BIGINT(11)
ALTER TABLE `customer` DROP `gender`;
drop:
drop database data_name
drop table tbl_name
ALTER TABLE `customer` DROP `gender`;
⇨ update:
UPDATE customer set cust_name="Akshay Nagar", pass="abc" where cus_id=2
⇨ delete:
delete from customer where cus_id=2
2) Outer Join
⇨ Full join
3) Cross Join
The CREATE INDEX statement is used to create indexes in tables.Indexes are used to retrieve data
from the database more quickly than otherwise. The users cannot see the indexes, they are just used
to speed up searches/queries 100 times faster. (SBI BANK find Account Number)
Type : 2 type
Views (Security Concept/ sub menu virtual table) Exa: (BANK DUPLICATE TABLE)
In SQL, a view is a virtual table based on the result-set of an SQL statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one or
more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the
data were coming from one single table.
Cursor
A cursor is a temporary work area created in the system memory when a SQL
statement is executed
Two Type :
Procedure :
A stored procedure is a prepared SQL code that you can save, so the code
can be reused over and over again.So if you have an SQL query that you write over
and over again, save it as a stored procedure, and then just call it to execute it.
In unm varchar(100),
In pass varchar(100),
In gen varchar(100),
In lag varchar(100),
In cid int(11),
in img varchar(100),
in status varchar(100)
Begin
End//
than
=>call insert_reg("avani","1234","Female","Hindi","1","demo.jpg","Unblock");
Trigger :
A MySQL trigger is a stored program (with queries) which is executed automatically to respond to a
specific event such as insertion, updation or deletion occurring in a table.
BEGIN
END//
Primary key – column of table whose value can be used to uniquely identify records
Foreign key – column inside table that is primary key of another table
Unique key – like primary key can be used to uniquely identify a record
Difference between primary key and unique key is primary key will never allow null where as unique
key will allow null values.Only One primary Key on table & unique key more one
The process of structuring data to minimize duplication and inconsistencies. The process usually
involves breaking down the single table into two or more tables and defining relationships between
those tables.
1NF
19) Type of CSS & how to load external file in other file?
<p style="color:red"></p>
<head>
<style>
p{ color:red }
</style>
</head>
3) External : create external page .css & load in <head> all websites page
style.css
Client OS :
It is an operating system that operates within a desktop. It is used to obtain services from a server. It
run on the client devices like laptop, computer and is very simple operating system
Web server: is a combination of software and hardware that outputs Web pages after receiving a
request from a client. Server-side scripting takes place on the server
comment
<?php
// This is a single-line comment
# This is also a single-line comment
/*
*/
?>
PHP Variables
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
● local : in function
● global : out of function
● static : static keywords
⇨ Operator:
⇨ Cond Loop:
PHP has more than 1000 built-in functions, and in addition you can create
your own custom functions.
What is an Array?
An array is a special variable, which can hold more than one value at a time.
array_combine / array_count_values
/array_diff/array_keys/array_values/array_merge/array_merge_recursive/array_sum/ array_sizeof /
in_array
string Function
implode/explode/strlen/strpos/strupper/strtolower
A session creates a file in a temporary directory on the server where registered session variables and
their values are stored. This data will be available to all pages on the site during that visit.
Sessions are wonderful ways to pass variables. All you need to do is start a session by
session_start();Then all the variables you store within a $_SESSION, you can access it from anywhere
in the server
Create : $_SESSION[‘var_name’]=”var_value”;
⇨ Cookies are small text files loaded from a server to a client computer storing some
information regarding the client computer, so that when the same page from the server is
visited by the user, necessary information can be collected from the cookie itself, decreasing
the latency to open the page
⇨ :setcookie(‘cookie_name’,’cookie_value’,time()+10)
⇨ print : $_COOKIE[‘cookie_name’’]
⇨ DELETE : setcookie(‘cookie_name’,’cookie_value’,time()-10)
⇨ $_SERVER is a PHP super global variable which holds information about headers, paths, and
script locations.
21) Explain $_GLOBALS with Examples ?
⇨ $GLOBALS is a PHP super global variable which is used to access global variables from
anywhere in the PHP script (also from within functions or methods).
⇨ PHP stores all global variables in an array called $GLOBALS[index]. The index holds the name
of the variable. The example below shows how to use the super global variable $GLOBALS
foreach use for array print in loop & also convert arr to string
foreach($arr as $value)
4 types
2. Notice Error:-These are trivial, non-critical errors. Accessing a variable that has not yet
been defined. But they do not termination script.
3. Parse error (Syntax error):-When we make mistake in PHP code like, missing semicolon or
any unexpected symbol in code. Stop Script Execution.
4. Warning Error (Most Serious error):-To include() a file which does not exist,but they do
not termination script
1. Speed. There is a difference between the two, but speed-wise it should be irrelevant
which one you use. echo is marginally faster
2. Expression. print() behaves like a function whereas echo behaves like a statement in that
you can do
3. Parameter(s). The grammar is: echo expression [, expression[,expression] ... ] But echo
( expression, expression ) is not valid. So, echo without parentheses can take multiple
parameters, which get concatenated
The include() and require() statement allow you to include the code contained in a PHP file within
another PHP file.
The include_once and require_once statements will only include the file once even if asked to
include it a second time i.e. if the specified file has already been included in a previous statement,
the file is not included again.
The date() function formats a local date and time, and returns the formatted date string.
date(format, timestamp)
date_default_timezone_set("Asia/Bangkok");
<?php
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
?>
Return the Unix timestamp for a date. Then use it to find the day of that date:
Numeric Arrays
What:An array with a numeric index. Values are stored and accessed in linear fashion.
Associative Arrays
What:An array with strings as index. This stores element values in association with key values rather
than in a strict linear index order.
Multidimensional Arrays
What:An array containing one or more arrays and values are accessed using multiple indices
base64_encode;
base64_decode
md5
sha1
SQL injection is a code injection technique that might destroy your database.SQL injection is one of
the most common web hacking techniques.SQL injection is the placement of malicious code in SQL
statements, via web page input.
SQL injection usually occurs when you ask a user for input, like their username/userid, and instead of
a name/id, the user gives you an SQL statement that you will unknowingly run on your database.
or
real_escape_string($_POST['firstname']);
29) What is the header function with an example ?
The header() function is a predefined PHP native function.With header() HTTP functions we can
control data sent to the client or browser by the Web server before some other output has been
sent.
The header function sets the headers for an HTTP Response given by the server. We can do all sorts
of things using the header function in PHP like Change page location, set timezone, set caching
control, etc...
header(‘location:mypage.php’);
header(‘refresh:5;mypage.php’);
header('Content-Type: application/pdf');
● Cookies are client-side files that contain user information, whereas Sessions are server-side
files that contain user information.
● Cookie is not dependent on session, but Session is dependent on Cookie.
● Cookie expires depending on the lifetime you set for it, while a Session ends when a user
closes his/her browser.
● The maximum cookie size is 4KB whereas in session, you can store as much data as you like.
● Cookie does not have a function named unsetcookie() while in Session you can use
Session_destroy(); which is used to destroy all registered data or to unset some
Typically the default is 24 minutes (1440 seconds), but your webhost may have altered the default
to something else.
===============================================================================
32) What is file handling & defining its mode and function ?
When we develop a web application using PHP, quite often we need to work with external
files, like reading data from a file or maybe writing user data into file etc. So it's important to
know how files are handled while working on any web application.
The fopen() function is also used to create a file. Maybe a little confusing, but in PHP, a file is created
using the same function used to open files
The first parameter of fwrite() contains the name of the file to write to and the
The first parameter of fread() contains the name of the file to read from and the
the feof() function checks if the "end-of-file" (EOF) has been reached.
After a call to the fgets() function, the file pointer has moved to the next line.
Modes Description
r Open a file for read only. File pointer starts at the beginning of the file
w Open a file for write only. Erases the contents of the file or creates a new file if it
doesn't exist. File pointer starts at the beginning of the file
a Open a file for write only. The existing data in file is preserved. File pointer starts at
the end of the file. Creates a new file if the file doesn't exist
x Creates a new file for write only. Returns FALSE and an error if file already exists
r+ Open a file for read/write. File pointer starts at the beginning of the file
w+ Open a file for read/write. Erases the contents of the file or creates a new file if it
doesn't exist. File pointer starts at the beginning of the file
a+ Open a file for read/write. The existing data in file is preserved. File pointer starts at
the end of the file. Creates a new file if the file doesn't exist
x+ Creates a new file for read/write. Returns FALSE and an error if file already exists
<script>
</script>
========================================================
: document.getElementById("demo");
The purpose of jQuery is to make it much easier to use JavaScript on your website.
jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and
wraps them into methods that you can call with a single line of code.
jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM
manipulation.
HTML/DOM manipulation
CSS manipulation
AJAX
Utilities
Tip: In addition, jQuery has plugins for almost any task out there.
Why jQuery?
There are lots of other JavaScript libraries out there, but jQuery is probably the
Many of the biggest companies on the Web use jQuery, such as:
Microsoft
IBM
Netflix
There are several ways to start using jQuery on your web site. You can:
Method-1
Downloading jQuery
Production version - this is for your live website because it has been minified and compressed
Development version - this is for testing and development (uncompressed and readable code)
The jQuery library is a single JavaScript file, and you reference it with the HTML <script> tag (notice
that the <script> tag should be inside the <head> section):
<head>
<script src="jquery-3.5.1.min.js"></script>
</head>
Method-2 Include jQuery from a CDN, like Google
jQuery CDN
If you don't want to download and host jQuery yourself, you can include it from a CDN (Content
Delivery Network).
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
You might have noticed that all jQuery methods in our examples, are inside a document ready event:
<script>
$(document).ready(function(){
});
</script>
This is to prevent any jQuery code from running before the document is finished loading (is ready).
All the different visitors' actions that a web page can respond to are called events.
Examples:
clicking on an element
The term "fires/fired" is often used with events. Example: "The keypress event is fired, the moment
you press a key".
Mouse Events
Keyboard Events
click
keypress
submit
load
dblclick
keydown
change
resize
mouseenter // event
hover() // action/function
keyup
focus
scroll
mouseleave
blur
unload
When users visit your website, they perform various activities such as clicking on text
and images and links, hover over defined elements, etc. These are examples of what
JavaScript calls events.
Keyboard Events
Mouse Events
Attribute Value Description
onmousemove script Fires when the mouse pointer is moving while it is over an
element
onmouseout script Fires when the mouse pointer moves out of an element
onmouseover script Fires when the mouse pointer moves over an element
onwheel script Fires when the mouse wheel rolls up or down over an element
Form Events
Events triggered by actions inside a HTML form (applies to almost all HTML elements, but is most
used in form elements):
Attribute Value Description
onblur script Fires the moment that the element loses focus
onchange script Fires the moment when the value of the element is changed
onfocus script Fires the moment when the element gets focus
onsearch script Fires when the user writes something in a search field (for
<input="search">)
onselect script Fires after some text has been selected in an element
● Xml was released in late 90’s. it was created to provide an easy to use and store
self describing data.
● XML tags are not predefined. You must define your own tags.
Platform Independent and Language Independent: The main benefit of xml is that
you can use it to take data from a program like Microsoft SQL, convert it into XML then
share that XML with other programs and platforms. You can communicate between two
platforms which are generally very difficult.
The main thing which makes XML truly powerful is its international acceptance. Many
corporation use XML interfaces for databases, programming, office application mobile
phones and more. It is due to its platform independent feature.
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
</note>
Ajax stands for Asynchronous Javascript And Xml. Ajax is just a means of loading data from the
server and selectively updating parts of a web page without reloading the whole page.
Basically, what Ajax does is make use of the browser's built-in XMLHttpRequest (XHR) object to send
and receive information to and from a web server asynchronously, in the background, without
blocking the page or interfering with the user's experience.
Ajax has become so popular that you hardly find an application that doesn't use Ajax to some extent.
The example of some large-scale Ajax-driven online applications are: Gmail, Google Maps, Google
Docs, YouTube, Facebook, Flickr, and so many other applications.
<script>
function loadDoc()
var xhttp;
} else {
//The onreadystatechange property defines a function to be executed when the readyState changes.
//The status property and the statusText property holds the status of the XMLHttpRequest object.
//readyState==4: request finished and response is ready
//status200: "OK"
xhttp.onreadystatechange = function()
if(xhttp.readyState==4 || xhttp.status==200)
document.getElementById("demo").innerHTML=this.responseText;
//To send a request to a server, we use the open() and send() methods of the XMLHttpRequest
object:
xhttp.send();
================================================================================
//jquery Ajax
// jquery ajax ;
<script>
function getdata(str)
$.ajax({
type: "POST",
url: "ajax_data",
data:"btn="+str,
success: function(data)
$("#search_Id").html(data) ;
});
}
</script>
From PHP5, you can also write PHP code in an object-oriented style.
Procedural programming is about writing procedures or functions that perform operations on the
data, while object-oriented programming is about creating objects that contain both data and
functions.
Example :
Class :
Define a Class
A class is defined by using the class keyword, followed by the name of the class and a pair of curly
braces ({}). All its properties and methods go inside the braces:
Define Objects
Classes are nothing without objects! We can create multiple objects from a class. Each object has all
the properties and methods defined in the class, but they will have different property values.
<?php
class abc
{
public $a=10;
public $b=30;
function sum()
{
echo $sum=$this->a+$this->b;
}
}
$obj= new abc;
$obj->sum();
?>
oops Features :
Class
Object
Encapsulation
Inheritance / Reusability
Polymorphism
Abstraction
interface
4. Multilevel Inheritance
40) what is an access modifier ? define the difference between private & protected ?
Access Modifiers (Access Specifiers) describes the scope of accessibility of an Object and its
members. We can control the scope of the member object of a class using access specifiers
PHP introduces the final keyword, which prevents child classes from
overriding a method by prefixing the definition with final. If the class itself is
An abstract method is a method that is declared, but not implemented in the code.
When inheriting from an abstract class, the child class method must be defined with the same name,
and the same or a less restricted access modifier. So, if the abstract method is defined as protected,
the child class method must be defined as either protected or public, but not private.
So, when a child class is inherited from an abstract class, we have the following rules:
The child class method must be defined with the same name and it redeclares the parent abstract
method
The child class method must be defined with the same or a less restricted access modifier
The number of required arguments must be the same. However, the child class may have optional
arguments in addition
<?php
simple function()
Interfaces are characterized similarly as a class, however, only the interface keyword replaces the
class phrase in the declaration and without any of the methods having their contents defined.
Interfaces are similar to abstract classes. The difference between interfaces and abstract classes are:
All interface methods must be public, while abstract class methods is public or protected
All methods in an interface are abstract, so they cannot be implemented in code and the abstract
keyword is not necessary
Classes can implement an interface while inheriting from another class at the same time
46) what is scope resolution (::) in PHP ?
The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double
colon, is a token that allows access to static, constant, and overridden properties or methods of a
class.
When referencing these items from outside the class definition, use the name of the class.
To access a static property use the class name, double colon (::), and the property name:
ClassName::staticMethod()/static_variable;
<?php
class greeting {
}
}
greeting::welcome();
?>
Const
Constants are one type of variable which we can define for any class with keyword const.
Class constants are different from normal variables, as we do not need $ to declare the class
constants.
If we are inside the class then values of the constants can be get using self keyword, but accessing
the value outside the class you have to use Scope Resolution Operator.
<?php
//create class
class javatpoint
echo javatpoint::a;
?>
Magic methods in PHP are special methods that are aimed to perform certain tasks. These methods
are named with double underscore (__) as prefix. All these function names are reserved and can't be
used for any purpose other than associated magical functionality. Magical method in a class must be
declared public. These methods act as interceptors that are automatically called when certain
conditions are met.
In simple word, type hinting means providing hints to function to only accept the given data type.
In technical word we can say that Type Hinting is method by which we can force function to accept
the desired data type.
In PHP, we can use type hinting for Object, Array and callable data type.
Since PHP 5 you can use type hinting to specify the expected data type of an argument
in a function declaration. When you call the function, PHP will check whether or not
the arguments are of the specified type. If not, the run-time will raise an error
<?php
print_r($guests);
?>
PHP only supports single inheritance: a child class can inherit only from one single parent.
So, what if a class needs to inherit multiple behaviors? OOP traits solve this problem.
Traits are used to declare methods that can be used in multiple classes. Traits can have methods and
abstract methods that can be used in multiple classes, and the methods can have any access
modifier (public, private, or protected).
<?php
trait message1 {
}
class Welcome {
use message1;
$obj->msg1();
?>
==================================================================================
===
PHP MVC is an application design pattern that separates the application data and business logic
(model) from the presentation (view). MVC stands for Model, View & Controller.
The car has the windscreens (view) which the driver (controller) uses to monitor traffic ahead then
speed or brake (model) depending on what he sees ahead.
As you can see in the figure, Java, .net, and PHP applications can communicate with
other applications through web service over the network. For example, the Java
application can interact with Java, .Net, and PHP applications. So web service is a
language independent way of communication.
Types of Web Services
There are mainly two types of web services.
web-based application using the REST, SOAP, WSDL, and UDDI over the
network. For example, Java web service can communicate with .Net application.
SOAP stands for Simple Object Access Protocol. It is a XML-based protocol for accessing web
services.
Exchanging data between applications is crucial in today’s networked world. But data exchange
between these heterogeneous applications would be complex. So will be the complexity of the
code to accomplish this data exchange.
SOAP is an XML based protocol. It is platform independent and language independent. By using
SOAP, you will be able to interact with other programming language applications.
RESTful Web Services are basically REST Architecture based Web Services. In REST Architecture
everything is a resource. RESTful web services are lightweight, highly scalable and maintainable and
are very commonly used to create APIs for web-based applications.
54) Difine Json_encode & jason_decode func with example ?
If you need to retrieve specific information from the server and make it appear on your website, you
will probably be using JSON. The name of JSON stands for JavaScript Object Notation. It is based on
JavaScript, so having some basic knowledge of it would be greatly welcome here. JSON also uses
JavaScript syntax.
JSON is commonly used for reading data out of a web server and displaying it on a website.
There are integrated functions to manipulate JSON. Most important of them are PHP
PHP frameworks streamline the the development of web applications written in PHP by providing a
basic structure for which to build the web applications. In other words, PHP frameworks help to
promote rapid application development (RAD), which saves you time, helps build more stable
applications, and reduces the amount of repetitive coding for developers. Frameworks can also
help beginners to build more stable apps by ensuring proper database interaction and coding on
the presentation layer. This allows you to spend more time creating the actual web application,
instead of spending time writing repetitive code.
● 1. Laravel
● 2. CodeIgniter
● 3. Symfony
● 4. Laminas Project
● 5. Phalcon
● 6. CakePHP
● 7. Yii
● 8. FuelPHP
1) Wordpress
2) Magento