PHP Interview Question Answer
What is the purpose of php.ini file?
php.ini is a default configuration file require for running application, we edit this as per our requirement
In xampp we can see this file on xampp->php->php.ini
Some php.ini setting we can do.
Increase memory limit
we can enable short tag
we can change max_execution_time
To enable or disable display error,log error,html error, log error ...
We can increase or decrease File uploading size
We can increase or decrease Maximum number of file upload
we can add/remove/comment extension like extension=php_mbstring.dll
How can we remove HTML Tags from Data?
How can we define a constant PHP?
define() is use to define constant
What is a Persistent Cookie?
A persistent cookie is permanently stored on Client computer this will create notepad file, But temporary cookie erased when we close broswer.
For Permanent cookie we use set_cookie()
For Temporary cookie we use $_SESSION
Full Form of PHP Open source softwares
XAMPP stands for Cross-Platform (X), Apache (A), MySQL (M), PHP (P) and Perl (P)
WAMP stands for Windows (W), Apache (A), MySQL (M) and PHP(P)
LAMP stands for Linux (L), Apache (A), MySQL (M) and PHP(P)
MacOS stands for MacOS (M), Apache (A), MySQL (M) and PHP(P)
Mysql Query to Find 2nd hightest salary from the employee table
SELECT DISTINCT salary FROM emp ORDER by salary desc LIMIT 1,1
SELECT (salary) FROM emp GROUP BY salary DESC LIMIT 1,1
SELECT salary FROM emp
WHERE salary = (SELECT (salary) FROM emp GROUP BY salary DESC LIMIT 1,1)
All above these query doing same work.
Swap two value without using third variable
MySQL storage engines
InnoDB is the most widely used storage engine with transaction support.
MyISAM is the original storage engine. It is a fast storage engine. It does not support transactions.
Memory storage engine creates tables in memory. It is the fastest engine.
CSV stores data in CSV files.
Merge operates on underlying MyISAM tables.
Archive storage engine is optimised for high speed inserting. It compresses data as it is inserted
The Blackhole storage engine accepts but does not store data. Retrievals always return an empty set.
Federated storage engine offers the ability to separate MySQL servers to create one logical database from many physical servers.
Difference between PHP5 and PHP7
In PHP7 New Spaceship Operator(<=>) Introduce
$a <=> $b;
Same as in PHP5 We use
$a>$b ? 1 : -1
echo $x>$y ? 1 : -1; //PHP5
echo $x<=>$y; //PHP7
In php 5 we can use mysql_* and mysqli_*, but in php mysql_* functions are completely removed, we use mysqli_* only
asp style tags(<% %>) and script tag(<script language="php"></script>) removed.
Function parameter type and Return type is possible.
What is the difference between unset() and unlink()?
unset() is sets a variable to undefined(means variable delete)
unlink() is use to delete file.
How can we get the IP address of the client?
$_SERVER["REMORTE_ADDR"] Superglobal variable is use to get IP Address
What is the output of the code?
$x = '71';
$y = &$x;
$y = "2$y";
What are SQL Injections?
SQL Injections are a method to print SQL Statement in browser. Hacker easily get information etc.
What is encapsulation?
An act of combining properties and methods, related to the same object, is known as encapsulation
When Import Data in phpmyadmin then Error show file size exceeded the maximum size permitted by your PHP configuration.
Follow theses steps
Open php.ini file
Search below code
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
we can change max 8M size here, then restart apache and mysql
What is array_combine()?
array_combine() function create an array by using keys and values. both array must be equal.
Array ( [A] => 50 [B] => 40 [C] => 50 )
What does array_count_values?
This function will counts all the values of an array
Array ( [Sunday] => 2 [Monday] => 2 [Tuesday] => 1 )
How to Convert Date to Unix time stamp and Unix time stamp to Date
strtotime()- Convert Date into Unix time stamp
echo(strtotime("now") . "<br>");
echo(strtotime("13 October 2018") . "<br>");
Date()- Convert Unix time stamp to Date
echo date("Y-m-d", $timestamp);
What is the difference between == and === operator?
== equal operator is use to check two value is equal or not. If we use === operator then it will check two value is equal with same data type
What is default session time?
what is the difference between include and include_once?
Include We include file many times in single script. Include_once This will include file only one time, second if we include this file this will be ignore
List data types in PHP ?