0% found this document useful (0 votes)
15 views

Core & Adv PHP Meterial

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Core & Adv PHP Meterial

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Core PHP Communication Technical

Charmi : B C

SHRUSTI C C

Vaibhavi B A

Dixit A A

Divya B B

Ravi B A

Hitanshi

Rajesh Sir : PHP Technical Que

1) What is PHP ?

● PHP personal Home Page


● PHP is an acronym for "PHP: Hypertext Preprocessor"
● PHP invent in 1994 by Rasmus Lerdorf
● PHP is a widely-used, open source server side scripting language
● PHP can generate dynamic page content
● PHP is a powerful tool for making dynamic and interactive Web pages.
● PHP scripts are executed on the server
● PHP is free to download and use
● PHP files can contain text, HTML, CSS, JavaScript, and PHP code
● PHP files have extension ".php"

2) PHP features ?

● Simple
● Interpreted
● Faster
● Open Source
● Platform Independent
● Case Sensitive
● Speed Comparison of ASP PHP JSP
● Simplicity
● More frameworks & CMS

3) Why did you choose PHP?

● PHP Inherit from c & c++


● PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
● PHP is compatible with almost all servers used today (Apache, IIS, etc.)
● PHP supports a wide range of databases
● PHP is free. Download it from the official PHP resource: www.php.net
● PHP is easy to learn and runs efficiently on the server side
● More frameworks & CMS

4) What is new in PHP 7 ?

● 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: <=>)

5) What software Eng SE ?

● state of the art of developing quality software on time and


within budget
● Trade-off between perfection and physical constraints
● SE has to deal with real-world issues
● State of the art!
● Community decides on best practice + life-long education

6) What are SDLC & its rules?

● 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

2. Analysis & SRS

3. Designing

4. Implementation (Coding)

5. Testing

6. Maintenance

7) What is DBMS & RDBMS and also Difference ?


o Database management system is a software which is used to manage the
database. For example: MySQL, Oracle, etc are a very popular commercial
database which is used in different applications.
o DBMS provides an interface to perform various operations like database creation,
storing data in it, updating data, creating a table in the database and a lot more.
o It provides protection and security to the database. In the case of multiple users,
it also maintains data consistency.

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.

DBMS + E.F. Codd 12 Rules = RDBMS.

8) What is SQL & TYPES?

● SQL stands for Structured Query Language


● SQL lets you access and manipulate databases

4 Types

1) DDL Data Definition Language ==== Total 4 types of Command


⇨ It is used to define structure of database and tables.
⇨ We can create, modify or delete structure of tables.
Create :

=>create database shop

=>create table customer(cus_id int PRIMARY key AUTO_INCREMENT, cust_name


varchar(100),user_name varchar(100), pass varchar(100),email varchar(100), mob bigint(11),
address varchar(255), pincode bigint(11), dob date, dotime time, dob_dt datetime )

1 foregn key

=>create table feedback(feed_id int PRIMARY key AUTO_INCREMENT, cus_id int(11),


fed_comment varchar(100), fed_date date, FOREIGN key(cus_id) REFERENCES
customer(cus_id));

2 foregn key

=>create table feedback(feed_id int PRIMARY key AUTO_INCREMENT, cus_id


int(11),pro_id(11) fed_comment varchar(100), fed_date date, FOREIGN key(cus_id)
REFERENCES customer(cus_id),FOREIGN key(pro_id) REFERENCES product(pro_id));

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`;

truncate: / delete all data from table /emty table


truncate table tabl_name

2) DML Data Manipulation Language


⇨ insert:
insert into customer(cust_name,user_name,pass,email,mobile,address,pincode,gender)
values("Akshay","akashay701","1234","[email protected]","5646944","Ahmedabad","325
874","Male")

⇨ update:
UPDATE customer set cust_name="Akshay Nagar", pass="abc" where cus_id=2

⇨ delete:
delete from customer where cus_id=2

3) DQL Data Query Language


⇨ Select Description: This will select ‘n‘ columns from table. Or To select all records from
database.

Select * from customer


Select cus_id,cust_name from customer
Select * from customer where cus_id=2
Select cus_id,cust_name from customer where cus_id=2

4) TCL Transaction Control Language


=> rollback / commit

9) ALL sql Queries ?

Above all Command Queries

10) Join queries


A JOIN clause is used to combine rows from two or more tables, based on a related column between
them.

Types Of Join : 3 Types

1) Inner Join /Join

select * from user_tbl join feedback on user_tbl.uid=feedback.uid where

select user_tbl.unm, feedback.* from user_tbl join feedback on user_tbl.uid=feedback.uid

customer order product

cust_id order_id prod_id

cust_name cust_id pro_name

pass prod_id pro_price

select * from order join customer on order.cust_id=customer.cust_id

join product on order.prod_id=product.prod_id

2) Outer Join

⇨ Left Outer Join


select * from user_tbl left outer join feedback on user_tbl.uid=feedback.uid

⇨ Right Outer Join


select * from user_tbl right outer join feedback on user_tbl.uid=feedback.uid

⇨ Full join

select * from user_tbl full join feedback

3) Cross Join

select * from user_tbl cross join feedback


11) index & Views in SQL

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

Simple: on only one table column

Composite : on more than 1 column in table

Syntex : CREATE INDEX user_ind ON user_tbl(uid,unm)

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.

CREATE VIEW reg_view AS SELECT uid,unm,gen,lag FROM reg

12) Cursor /Procedure/Trigger

Cursor

A cursor is a temporary work area created in the system memory when a SQL

statement is executed

Two Type :

Implicit : DML statement insert/update/delete/ Select only one row

Explicit : Select more than one row data

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.

Create procedure insert_reg(

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

insert into reg(unm,pass,gen,lag,cid,img,status) values(unm,pass,gen,lag,cid,img,status);

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.

BEFORE INSERT – activated before data is inserted into the table.

AFTER INSERT- activated after data is inserted into the table.

BEFORE UPDATE – activated before data in the table is updated.

AFTER UPDATE - activated after data in the table is updated.

BEFORE DELETE – activated before data is removed from the table.

AFTER DELETE – activated after data is removed from the table

=>create table reg_log( uid int(100),unm varchar(100),pass varchar(100),gen varchar(100),lag


varchar(100),cid varchar(100),img varchar(100),status varchar(100),entry_date_time datetime);

=>CREATE TRIGGER insert_trigger_reg BEFORE INSERT ON reg FOR EACH ROW

BEGIN

insert into reg_log(uid,unm,pass,gen,lag,cid,img,status,Entry_date_time) values


(new.uid,new.unm,new.pass,new.gen,new.lag,new.cid,new.img,new.status,now());

END//

13) Aggregate Function // Use all in Select Command

⇨ AVG() Returns the average value


⇨ MIN() Returns the smallest value
⇨ MAX() Returns the largest value
⇨ SUM() Returns the sum
⇨ COUNT() Returns the number of rows
⇨ FIRST() Returns the first value
⇨ LAST() Returns the last value

SELECT MIN(Price) AS SmallestPrice FROM Products;

14) Order by/group by/limit/between/like


SELECT * FROM Customers ORDER BY Country;
SELECT * FROM Customers WHERE CustomerName LIKE 'a%' / ‘%s’ /
‘%s%’ ‘[abc]%’;

15) What is Diffe between PK & fk ?

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

16) What is Normalization?

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

2NF after 1NF

3NF after 2NF

17) Advance Sql

Index : query 100 time faster 1) simple 2) Composite

Views : Security concept sub table/ duplicate table

Procedure & function: Create procedure like INSERT/UPDATE/DELETE/SELECT


Cursor : temporary work area create in memory

1) Implicit // DML and select one row


2) Explicit // select more than one row

18) what's new in HTML 5 ? like doctype / input type

⇨ The most interesting new HTML5 elements are:


⇨ New semantic elements like <header>, <footer>, <article>, and <section>.
⇨ New attributes of form elements like number, date, time, calendar, and range.
⇨ New graphic elements: <svg> and <canvas>.
⇨ New multimedia elements: <audio> and <video>.

19) Type of CSS & how to load external file in other file?

● CSS stands for Cascading Style Sheets


● CSS describes how HTML elements are to be displayed on screen,
paper, or in other media
● CSS saves a lot of work. It can control the layout of multiple web pages
all at once
● External stylesheets are stored in CSS files

1)Inline CSS: use in direct tag by style attribute

<p style="color:red"></p>

2) Internal CSS : use for one page

<head>
<style>
p{ color:red }
</style>
</head>

3) External : create external page .css & load in <head> all websites page

style.css

<link href="style.css" type="text/css" rel="stylesheet">

3) External css // use as external .css page

<link href=”style.css” type=”text/css” rel=”stylesheet” >


20) Explain Bootstrap class =>

Container class/form class / table class /button class/Grid class

21) What is server & Client & Difference?

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

22) Core PHP

syntex <?php ?> <? ?>

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;
?>

PHP has three different variable scopes:

● local : in function
● global : out of function
● static : static keywords

PHP Data Types


● String
● Integer
● Float (floating point numbers - also called double)
● Boolean
● Array
● Object
● NULL
● Resource

⇨ Operator:

● Arithmetic operators +-*/%


● Assignment operators = += -+ *= /= %= a+=y / a=a+y
● Comparison operators == != > < >= <= ===(value type)
● Increment/Decrement operators ++ --
● Logical operators && || !
● String operators . .=
● Array operators
● Conditional assignment operators/ turnory (cond)? ” yes ”: “no”

⇨ PHP Conditional Statements:


IF /IF ELSE / IF ELSEIF ELSE / NESTED IF / SWITCH

⇨ Cond Loop:

⇨ while/do while /for /forecah / break /continue


PHP Functions
The real power of PHP comes from its functions.

PHP has more than 1000 built-in functions, and in addition you can create
your own custom functions.

1) PHP Built-in Functions


2) PHP User Defined Functions

What is an Array?
An array is a special variable, which can hold more than one value at a time.

● Indexed arrays/numeric - Arrays with a numeric index


● Associative arrays - Arrays with named keys
● Multidimensional arrays - Arrays containing one or more arrays

PHP - Sort Functions For Arrays


● sort() - sort arrays in ascending order
● rsort() - sort arrays in descending order
● asort() - sort associative arrays in ascending order, according to the
value
● ksort() - sort associative arrays in ascending order, according to the
key
● arsort() - sort associative arrays in descending order, according to
the value
● krsort() - sort associative arrays in descending order, according to
the key

Array all Function ;

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

For Password encryption & decryption :base64_encode - base64_decode / md5 / sha1

include- include_once & diff

require -require_once & dife

dife between include and require ==== warning === fetal_errror


17) PHP GLOBALS Variable?

=> A global variable is a predefined variable.

⇨ A global variable is a programming language construct, a variable type that is declared


outside any function and is accessible to all functions throughout the program.
⇨ $GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE
$_SESSION

18) Explain Session with Example?

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”;

use : echo $_SESSION[‘var_name’];

delete single: unset($_SESSION[‘var_name’]);

delete all : session_destroy();

19) Explain Cookie with Example?

⇨ 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)

20) Explain $_SERVER with Example?

⇨ $_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

22) Explain foreach with Example?

foreach use for array print in loop & also convert arr to string

foreach($arr as $value)

23) Types of Error?

4 types

1. Fatal Error (Critical error):-An object of a non-existent class, or calling a non-existent


function. These errors cause the immediate termination of the script.

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

24) Difference between echo and print()?

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

25) What diff between include & require?

The include() and require() statement allow you to include the code contained in a PHP file within
another PHP file.

Include : if file not exist : Warning error

Require : if file not exist : Fatal error


26) What diff between include_once & include ?

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.

23) date() function ?

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);

echo $diff->format("%R%a days");

?>

24) for future date MKTIME with practical ?

Return the Unix timestamp for a date. Then use it to find the day of that date:

25) what is array & type of array ?

An array is a collection of items stored at contiguous memory locations.

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

26) define implode() & explode() & in_array()

implode() // convert array variable to string variable

explode() // convert string variable to array variable

in_array() // find value in array & use only in if(“Hindi”,$lag)

27) define encryption & decryption function ?

For password enc & dec

base64_encode;

base64_decode

md5

sha1

28) what is sql Injection & with function & example ?

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.

txtUserId = getRequestString("UserId"); /$_REQUEST[‘Userid’]

txtSQL = "SELECT * FROM Users WHERE UserId = " + txtUserId;

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');

30) difference between session & cookie ?

● 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

31) What is the default session expired time ?

It depends on the server configuration or the relevant directives session.gc_maxlifetime in php.ini.

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

second parameter is the string to be written

The first parameter of fread() contains the name of the file to read from and the

second parameter specifies the maximum number of bytes to read


The fclose() function is used to close an open file.

the feof() function checks if the "end-of-file" (EOF) has been reached.

The fgets() function is used to read a single line from a file.

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

33) what is javascript/extesion/external file/syntex & use of javascript ?

JavaScript is used in client side and also server side

JavaScript is mainly used in client side


JavaScript is the Programming Language for the Web.

JavaScript can update and change both HTML and CSS.

JavaScript can calculate, manipulate and validate data.

files save as .js extension & call

<script type="text/javascript" src="file.js"> </script>


Syntex

<script>

</script>

javascript code add in head section and body section

========================================================

: document.getElementById("demo");

Variable/array/operator/loop/function/ func with argument & also


know html event
Validation Task by ID OR BY FORMS

34) what is jquery/extension/external file/syntax & use of jquery?

jQuery is a lightweight, "write less, do more"JavaScript library.

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.

The jQuery library contains the following features:

HTML/DOM manipulation

CSS manipulation

HTML event methods

Effects and animations

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

most popular, and also the most extendable.

Many of the biggest companies on the Web use jQuery, such as:

Google

Microsoft

IBM

Netflix

There are several ways to start using jQuery on your web site. You can:

Method-1

Download the jQuery library from jQuery.com

Downloading jQuery

There are two versions of jQuery available for downloading:

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)

Both versions can be downloaded from jQuery.com.

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).

Google is an example of someone who host jQuery:

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>

The Document Ready Event

You might have noticed that all jQuery methods in our examples, are inside a document ready event:

<script>

$(document).ready(function(){

// jQuery methods go here...

});

</script>

This is to prevent any jQuery code from running before the document is finished loading (is ready).

What are Events?

All the different visitors' actions that a web page can respond to are called events.

An event represents the precise moment when something happens.

Examples:

moving a mouse over an element


selecting a radio button

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".

Here are some common DOM events:

Mouse Events

Keyboard Events

Form Events Document/Window Events

click

keypress

submit

load

dblclick

keydown

change

resize

mouseenter // event

hover() // action/function

keyup

focus

scroll

mouseleave

blur

unload

35) Event in javascript & popup?

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

Attribute Value Description

onkeydown script Fires when a user is pressing a key

onkeypress script Fires when a user presses a key

onkeyup script Fires when a user releases a key

Mouse Events
Attribute Value Description

onclick script Fires on a mouse click on the element

ondblclick script Fires on a mouse double-click on the element

onmousedown script Fires when a mouse button is pressed down on an element

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

onmouseup script Fires when a mouse button is released over an element

onmousewheel script Deprecated. Use the onwheel attribute instead

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

oncontextmenu script Script to be run when a context menu is triggered

onfocus script Fires the moment when the element gets focus

oninput script Script to be run when an element gets user input

oninvalid script Script to be run when an element is invalid

onreset script Fires when the Reset button in a form is clicked

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

onsubmit script Fires when a form is submitted


1) alert(‘only ok button’);
2) confirm(‘ok & cancel button’);
3) prompt(‘ok cancel & text box’);

36) what is XML & use of example with example ?

● Xml (eXtensible Markup Language) is a markup language.

● XML is designed to store and transport data.

● Xml was released in late 90’s. it was created to provide an easy to use and store
self describing data.

● XML became a W3C Recommendation on February 10, 1998.

● XML is not a replacement for HTML.

● XML is designed to be self-descriptive.

● XML is designed to carry data, not to display data.

● XML tags are not predefined. You must define your own tags.

● XML is platform independent and language independent.

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.

<?xml version="1.0" encoding="UTF-8"?>

<note>

<to>Tove</to>

<from>Jani</from>

<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>

</note>

The Difference Between XML and HTML


XML and HTML were designed with different goals:

● XML was designed to carry data - with focus on what data is


● HTML was designed to display data - with focus on how data looks
● XML tags are not predefined like HTML tags are

37) What is ajax javascript/jquery and use of ajax with example ?

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.

//ajax code by javascript

<script>

function loadDoc()

var xhttp;

if (window.XMLHttpRequest) // create object for request

// code for modern browsers

xhttp = new XMLHttpRequest();

} else {

// code for IE6, IE5

xhttp = new ActiveXObject("Microsoft.XMLHTTP");

//The readyState property holds the status of the XMLHttpRequest.

//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)

//The responseText property returns the server response as a JavaScript string,


and you can use it accordingly:

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.open("GET", "data.php", true);

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>

38) What is OOPS and its features ?

From PHP5, you can also write PHP code in an object-oriented style.

OOP stands for Object-Oriented Programming.

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.

Object-oriented programming has several advantages over procedural programming:

● OOP is faster and easier to execute


● OOP provides a clear structure for the programs
● OOP helps to keep the PHP code DRY "Don't Repeat Yourself", and makes the code easier to
maintain, modify and debug
● OOP makes it possible to create full reusable applications with less code and shorter
development time

Example :

Class === Fruits / car

Object ==== apple,banana,orange / volve audi ford

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.

Objects of a class are created using the new keyword.

<?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

Access Modifier / Visibility

Polymorphism

Abstraction

interface

Constructor & Destructor

39) what is inheritance & its type ?

Inheritance is the process of creating a new Class, called the Derived


Class , from the existing class, called the Base Class . The Inheritance
has many advantages, the most important of them being the
reusability of code. Rather than developing new Objects from
scratch, new code can be based on the work of other developers,
adding only the new features that are needed. The reuse of existing
classes saves time and effort.
1. Single Inheritance

2. Multiple Inheritance // not extends multiple class


3. Hierarchical Inheritance

4. Multilevel Inheritance

5. Hybrid Inheritance (also known as Virtual 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

1) Public Access level is not restricted. available out of class


2) Protected : available in own class and child (inheritance class)
3) Private Access level is limited available only in own class.

41) What is Polymorphism & diffe between overloading & overriding ?

According to the Polymorphism principle, methods in


different classes that do similar things should have the same
name.
=>Overloading Same method name with different signature/different
argument, since PHP doesn't support method overloading concept
=> Overriding When same methods defined in parents and child class
with same signature/same argument
42) what is the final keyword & final function ?

PHP introduces the final keyword, which prevents child classes from

overriding a method by prefixing the definition with final. If the class itself is

being defined final then it cannot be extended.

43) what is a constructor & destructor with example ?

In object oriented programming terminology, constructor is a method defined inside a


class that is called automatically at the time of creation of object. Purpose of a
constructor method is to initialize the object. In PHP, a method of special name
__construct acts as a constructor.
=> class name & function name are same thats called constructor

In PHP, destructor method is named as __destruct. During shutdown sequence too,


objects will be destroyed. Destructor method doesn't take any arguments, neither
does it return any data type

44) what is an abstract class in PHP?

An abstract class or method is defined with the abstract keyword:

An object of an abstract class can't be made.

An abstract class is a class that contains at least one abstract method.

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

abstract class ParentClass {

abstract public function someMethod1();

abstract public function someMethod2($name, $color);

abstract public function someMethod3() : string;

simple function()

45) what is the interface in PHP?

Interfaces are declared with the interface keyword:

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 allow you to specify what methods a class should implement.

PHP - Interfaces vs. Abstract Classes

Interfaces are similar to abstract classes. The difference between interfaces and abstract classes are:

Interfaces cannot have properties, while abstract classes can

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.

47) define diff between static & const keywords in PHP ?

Static properties can be called directly - without creating an instance of a class.

Static properties are declared with the static keyword:

To access a static property use the class name, double colon (::), and the property name:

ClassName::staticMethod()/static_variable;

<?php

class greeting {

public static function welcome() {

echo "Hello World!";

}
}

// Call static method

greeting::welcome();

?>

Const

Constants are one type of variable which we can define for any class with keyword const.

Value of these variables cannot be changed anyhow after assigning.

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

//create constant variable

const a= "This is const keyword example";

//call constant variable.

echo javatpoint::a;

?>

48) What is magic function in PHP?

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.

Following magical methods are currently available in PHP

__construct(), __destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(), __sleep(),


__wakeup(), __serialize(), __unserialize(), __toString(), __invoke(), __set_state(), __clone() and
__debugInfo()
49) what is type Hinting in PHP?

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

and execution will be halted.

<?php

function startParty(array $guests)

print_r($guests);

startParty(array("Susan Foreman", "Sarah Jane Smith", "Rose Tyler", "Donna Noble"));

?>

50) What is trait in PHP ?

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 declared with the trait keyword: as class

To use a trait in a class, use the use keyword: // for inheritance

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 {

public function msg1() {

echo "OOP is fun! ";

}
class Welcome {

use message1;

$obj = new Welcome();

$obj->msg1();

?>

==================================================================================
===

51)What is PHP MVC framework?

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 controller mediates between the models and views.

Think of the MVC design pattern as a car and the driver.

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.

Why use PHP MVC Framework?

● PHP MVC Frameworks simplify working with complex technologies by;


○ Hiding all the complex implementation details
○ Providing standard methods that we can use to build our applications.
○ Increased developer productivity, this is because the base implementation of
activities such as connecting to the database, sanitizing user input etc. are already
partially implemented.
○ Adherence to professional coding standards
52) What are web services ?

A Web Service is can be defined by following ways:

● It is a client-server application or application component for communication.

● The method of communication between two devices over the network.

● It is a software system for the interoperable machine to machine communication.

● It is a collection of standards or protocols for exchanging information between two


devices or application.

Let's understand it by the figure given below:

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.

53) define web services plateform ?

SOAP Web Services

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 a W3C recommendation for communication between two applications.

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

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 anonymous data that can be translated in PHP variables.

Arrays can be converted to JSON format.

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

json_encode() and PHP json_decode().

55) what is framework & its example ?

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

55) What is CMS & its example ?

Content Management System

1) Wordpress
2) Magento

You might also like