PHP Interview Questions

Latest PHP Questions and Answers

PHP Interview Questions and Answers ->

What is PHP?
-->
PHP (Hyper text Pre Processor) is a scripting language commonly used for web applications. PHP can be easily embedded in HTML. PHP generally runs on a web server. It is available for free and can be used across a variety of servers, operating systems and platforms.
What are the differences between GET and POST methods in form submitting, give the case where we can use get and we can use post methods?
-->
On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.

On the browser side, the difference is that data submitted by the GET method will be displayed in the browser's address field. Data submitted by the POST method will not be displayed anywhere on the browser.

GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data.
Who is the father of php and explain the changes in php versions?
-->
Rasmus Lerdorf for version changes go to http://php.net/ Marco Tabini is the founder and publisher of php|architect.
How can we submit from without a submit button?
-->
We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form.
How many ways we can retrieve the date in result set of mysql Using php?
-->
As individual objects so single record or as a set or arrays.
What is the difference between $message and $$message?
-->
They are both variables. But $message is a variable with a fixed name. $$message is a variable who's name is stored in $message. For example, if $message contains "var", $$message is the same as $var.
What are the differences between require and include, include_once?
-->
File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.
What are the different tables present in mysql?
-->
Total 5 types of tables we can create

1. MyISAM

2. Heap

3. Merge

4. InnoDB

5. ISAM

6. BDB

MyISAM is the default storage engine as of MySQL 3.23.
How can I execute a php script using command line?
-->
Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.

Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.
What is meant by nl2br()?
-->
Nl2br Inserts HTML line breaks before all newlines in a string string nl2br (string); For example: echo nl2br("god bless you")

will output "god bless you" to your browser.
What are the current versions of apache, php, and mysql?
-->
PHP: php 5.3
MySQL: MySQL 5.5
Apache: Apache 2.2
What are the reasons for selecting lamp (Linux, apache, mysql, php) instead of combination of other software programs, servers and operating systems?
-->
All of those are open source resource. Security of linux is very very more than windows. Apache is a better server that IIS both in functionality and security. Mysql is world most popular open source database. PHP is more faster that asp or any other scripting language.
How can we encrypt and decrypt a data present in a mysql table using mysql?
-->
AES_ENCRYPT () and AES_DECRYPT ()
How can we encrypt the username and password using php?
-->
You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD("Password"); We can encode data using base64_encode($string) and can decode using base64_decode($string);
What are the different types of errors in php?
-->
E_ERROR: A fatal error that causes script termination
E_WARNING: Run-time warning that does not cause script termination
E_PARSE: Compile time parse error.
E_NOTICE: Run time notice caused due to error in code
E_CORE_ERROR: Fatal errors that occur during PHP's initial startup (installation)
E_CORE_WARNING: Warnings that occur during PHP's initial startup
E_COMPILE_ERROR: Fatal compile-time errors indication problem with script.
E_USER_ERROR: User-generated error message.
E_USER_WARNING: User-generated warning message.
E_USER_NOTICE: User-generated notice message.
E_STRICT: Run-time notices.
E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
E_ALL: Catches all errors and warnings
What is the functionality of the function htmlentities?
-->
Answer: htmlentities Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.
What is meant by urlencode and urldocode?
-->
Urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25?. URL encoded strings are safe to be used as part of URLs.
urldecode() returns the URL decoded version of the given string.
What is the difference between the functions unlink and unset?
-->
Unlink() deletes the given file from the file system.
unset() makes a variable undefined.
How can we register the variables into a session?
-->
We can use the session_register ($ur_session_var) function.
How can we get the properties (size, type, width, height) of an image using php image functions?
-->
To know the Image type use exif_imagetype () function
To know the Image size use getimagesize () function
To know the image width use imagesx () function
To know the image height use imagesy() function
What is the maximum size of a file that can be uploaded using php and how can we change this?
-->
You can change maximum size of a file set upload_max_filesize variable in php.ini file.
How can we increase the execution time of a php script?
-->
Set max_execution_time variable in php.ini file to your desired time in second.
How can we take a backup of a mysql table and how can we restore it.?
-->
Create a full backup of your database: shell> mysqldump tab=/path/to/some/diropt db_name Or: shell> mysqlhotcopy db_name /path/to/some/dir The full backup file is just a set of SQL statements, so restoring it is very easy:

shell> mysql "."Executed";
mysql_close($link2);
How many ways can we get the value of current session id?
-->
session_id() function returns the session id for the current session.
How can we destroy the session, how can we unset the variable of a session?
-->
session_destroy
session_unset
How can we destroy the cookie?
-->
Set same the cookie in past
What is the difference between ereg_replace() and eregi_replace()?
-->
eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.
How can we know the count/number of elements of an array?
-->
2 ways
a) sizeof($urarray) This function is an alias of count()
b) count($urarray)
interestingly if u just pass a simple var instead of a an array it will return 1.
What is the maximum length of a table name, database name, and fieldname in mysql?
-->
Database name- 64
Table name -64 Fieldname-64
How many values can the SET function of mysql takes?
-->
Mysql set can take zero or more values but at the maximum it can take 64 values
What is maximum size of a database in mysql?
-->
If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint.
The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected.
The amount of available disk space limits the number of tables.
MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 â€" 1 bytes). With this larger allowed table size, the maximum effective table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits.
The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB.
The following table lists some examples of operating system file-size limits. This is only a rough guide and is not intended to be definitive. For the most up-to-date information, be sure to check the documentation specific to your operating system.
Operating System File-size Limit
Linux 2.2-Intel 32-bit 2GB (LFS: 4GB)
Linux 2.4+ (using ext3 filesystem) 4TB
Solaris 9/10 16TB
NetWare w/NSS filesystem 8TB
Win32 w/ FAT/FAT32 2GB/4GB
Win32 w/ NTFS 2TB (possibly larger)
MacOS X w/ HFS+ 2TB
What is meant by MIME?
-->
Multipurpose Internet Mail Extensions.
WWW ability to recognise and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types.
What is meant by PEAR in php?
-->
PEAR is short for "PHP Extension and Application Repository" and is pronounced just like the fruit. The purpose of PEAR is to provide:
A structured library of open-sourced code for PHP users
A system for code distribution and package maintenance
A standard style for code written in PHP
The PHP Foundation Classes (PFC),
The PHP Extension Community Library (PECL),
A web site, mailing lists and download mirrors to support the PHP/PEAR community
PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then.

http://pear.php.net/manual/en/about.pear.php
What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
-->
Mysql_fetch_array Fetch a result row as an associative array, a numeric array, or both.
mysql_fetch_object ( resource result )
Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows
mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.
What is PHP?
-->
PHP Version 3.0 is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.
What is the difference between include and require?
-->
If you require a file and it cannot be found, the script will terminate with a fatal error. If you use include then you will get an error but the script will continue to execute. Therefore when the information you wish to reference from another file is essential to the correct running of a page, use require.
Is PHP a case sensitive programming language?
-->
PHP is a partially case sensitive programming language. We can use function names, class names in case insensitive manner.
What is mean by LAMP?
-->
LAMP means combination of Linux, Apache, MySQL and PHP.
How do you get the user's ip address in PHP?
-->
Using the server variable: $_SERVER['REMOTE_ADDR']
How do you make one way encryption for your passwords in PHP?
-->
Using md5 function or sha1 function
What is meant by PEAR in php?
-->
Answer1: PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install "packages"
Answer2:
PEAR is short for "PHP Extension and Application Repository" and is pronounced just like the fruit. The purpose of PEAR is to provide:
A structured library of open-sourced code for PHP users
A system for code distribution and package maintenance
A standard style for code written in PHP
The PHP Foundation Classes (PFC),
The PHP Extension Community Library (PECL),
A web site, mailing lists and download mirrors to support the PHP/PEAR community
PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then.
How can we repair a MySQL table?
-->
The syntex for repairing a mysql table is:

REPAIR TABLE tablename
REPAIR TABLE tablename QUICK
REPAIR TABLE tablename EXTENDED

This command will repair the table specified.
If QUICK is given, MySQL will do a repair of only the index tree.
If EXTENDED is given, it will create index row by row.
What is the difference between echo and print statement?
-->
Echo() can take multiple expressions,Print cannot take multiple expressions.

Print return true or false based on success or failure whereas echo just does what its told without letting you know whether or not it worked properly.
What are the features and advantages of OBJECT ORIENTED PROGRAMMING?
-->
One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns.

For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.

Credits:http://www.w3schools.in.
By Jilani Shaikh

Best Training Institute

Blend InfoTech offers methodology ensures that lessons are practical, and involve the participants, who engage in meaningful and Best Training and tasks that reflect communicative demands of IT Industry.Best Training Institute Deccan - 8087088772 | Akurdi - 8793008772 | Dange Chawk (Wakad) - 8983028772

Call NOW: 9595 772772

Register Now

Why Blend?

Blend's Benefits to Student:

  • Hands on Project Experience exposures in the Lab session
  • Real Time case studies to practice
  • Free Technical Support after Course Completion
  • Back up Classes Available
  • LAB Facility 
  • Free Wifi to learn subject
  • Latest Study Material
  • Fast Track and Normal Batches available

100% Guaranteed Placement Assistance

  • We send you for interviews till you get a job
  • We get your Resume Ready to attend interviews
  • Interview Preparation Support
  • Write Technical Exams before attending Interviews
  • Mock Interviews
  • Pre-Requisite: Job Seekers, any Graduates, Software Developer, Fresher , web developers, web designers, SEO specialists
  • Projects: You Work on Live Projects
  • Latest and Update Course Contents as per corporate standards.
  • Personal Attention to make Students Web Developer Experts

Deccan

1st Floor, Deccan Corner,
Opp. R-Deccan Mall/ KFC,
Near Deccan Bus stop
J.M Road, Deccan
Pune- 04.
Office: 020-60708772,
Cell: 8087088772

Akurdi (Nigdi) (HO)

7/1 Shreeyash Building,
Opp. Akurdi Railway Station,
Dharmaraj Chowk.
Nigdi (Akurdi) -44
Phone: (020) 64108772
Mob: 8793008772

Dange Chowk (Chinchwad)

Mayuri Plaza,
Above SBI Bank,
Dange Chowk (Thergav).
Chinchwad 33.
Phone: (020) 65108772
Mob: 8983028772

Karve Road

Prasad Apartment
Opp. Bank Of India & Indian Overseas bank
Nalstop, Pune-4
Phone: (020) 60708772
Mob: 8087088772

Quick Connect