Showing posts with label php-interview-questions-answers. Show all posts
Showing posts with label php-interview-questions-answers. Show all posts

555 php Interview Questions

  • How can we get the browser properties using PHP?
  • What is the purpose of the following files having extensions 1) .frm 2) .myd 3) .myi? What do these files contain?
  • sorting an array?
  • What is maximum size of a database in MySQL?
  • Give the syntax of Grant and Revoke commands?
  • Explain Normalization concept?
  • How can we find the number of rows in a table using MySQL?
  • How can we find the number of rows in a result set using PHP?
  • How many ways we can we find the current date using MySQL?
  • What are the advantages and disadvantages of Cascading Style Sheets?
  • What type of inheritance that PHP supports?
  • How show an image from mysql?
  • How  group the results of a mysql query?
  • How can increase the performance of MySQL select query?
  • What are the advantages/disadvantages of MySQL and PHP?
  • What is the difference between GROUP BY and ORDER BY in Sql?
  • What is the difference between char and varchar data types?
  • What is the functionality of md5 function in PHP?
  • How can I load data from a text file into a table?
  • How can we know the number of days between two given dates using MySQL?
  • How can we know the number of days between two given dates using PHP?
  • How can we change the name of a column of a table?
  • How can we change the name and data type of a column of a table?
  • What are the differences between drop a table and truncate a table? 
  • How do I sort an array by key?
  • When you want to show some part of a text displayed on an HTML page in red font color, what different possibilities are there to do this? What are the advantages/disadvantages of these methods?
  • When viewing an HTML page in a Browser, the Browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?
  • What are the different methods of passing data or information between two calls of a web page? What are the advantages/disadvantages of these methods?
  • An Apache web server is running on a Linux system. Suddenly, the web server delivers the pages very slow. How could you find out possible reasons for that (when using system commands, please specify their names)?
  • What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?
  • Please give a regular expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag. Example: The regular expression should match the tag <A HREF=”http://www.yoursite.com/”> and give the URL (”http://www.yoursite.com /”) as a return result. Tags should also be matched if they contain other attributes than the HREF attribute.
  • A select query over a large table runs very slow because of the growing number of entries in that table. What different measures could be taken to improve speed?
  • A company wants to store their invoices in a database. They already have their customers and articles in that database. Both customer and article are each identified by an unique integer value. Please create the SQL statements for creating the necessary table(s) for storing the invoices in a MySQL database. An invoice should hold information like invoice number, customer, date, article(s) and quantity etc.
  • For the database from the previous question, please give an SQL query which returns the invoice number of all invoices which contain the article with the number “1234″. The query should be able to run under a MySQL 4.0 database.
  • How would you backup and restore a big MySQL database? What are the advantages of the approach which you have taken over the others?
  • Create a PHP web script with the following attributes: on start, three HTML form elements are shown: an string input field, a checkbox field, a dropdown/pull down list with 5 elements and a submit button. On submission, the form should be redisplayed (while remaining all options/inputs as the user has selected/entered them). Additionally, the selections/inputs of the user should be displayed in text. Please solve this without the use of any external libraries.
  • What is MIME?
  • What is PEAR in PHP?
  • How can I use the COM components in PHP?
  • How can I load the DLLs dynamically?
  • How many ways we can give the output to a browser?
  • How can we know that a session is started or not?
  • What is the default session time in PHP and how can I change it?
  • What changes I have to done in PHP.ini file for file uploading?
  • What are the differences between MySQL_fetch_array(), MySQL_fetch_object(), MySQL_fetch_row()?
  • How can I set a cron and how can i execute it in Unix, Linux, and windows?
  • Steps for the payment gateway processing?
  • How can I rotate an image?
  • find the longest value in my mysql table?
  • How many ways I can register the variables into session?
  • Explain different types of errors in PHP (i.e. arguments in errorreporting function)?
  • How many ways I can redirect a PHP page?
  • List out different arguments in PHP header function?
  • What type of headers have to add in the mail function in which file a attached?
  • What is the difference between <?PHP and <? And which is preferable?
  • What are the differences between include() and include_once() functions?
  • Describe the importance of database abstraction layers in PHP and database connection?
  • Explain MySQL optimization?
  • How do I order the results of my query?
  • What is the difference between using copy() and move() function in PHP file uploading?
  • What is the difference between Reply-to and Return-path in the headers of a mail function?
  • Explain about Type Juggling in PHP?
  • How do I check for an empty field in a form?
  • How can I get the only name of the current executing file?
  • How can I embed a Java program in PHP file and what changes have to be done in PHP.ini file?
  • How can I find what type of images that the PHP version supports?
  • How can I access information sent through POST on a form?
  • What is the difference between a framework, IDE, CMS, Blog
  •  remove HTML tags from a string?
  • What is the difference between client side validation and server side validation? 
  • How can I add text to an image?
  • What is a static variable within a function?
  • What are key tasks for Php executive?
  • $_ENV and $_SERVER ?
  • Cookies Versus Sessions?
  • What is the use of PEAR in php?
  • What Is a Function?
  • $_GET , $_POST,$_COOKIE??
  • Associative Arrays?
  • magic_quotes_gpc, magic_quotes_runtime?
  • What are the different tables present in mysql?
  • What is SQL Injection?
What are encryption functions in PHP?
ans-CRYPT,MD5

How to create a mysql connection?
mysql_connect(servername,username,password);

<?php
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
What is SSL ?
 SSL stands for Secure Sockets Layer.The Secure Sockets Layer (SSL) is a commonly-used protocol for managing the security of a message transmission on the Internet.

 Finding the Current Date and Time?
 ans-
Use strftime( ) or date( ) for a formatted time string:
print strftime('%c');
print date('r');
Mon Aug 12 18:23:45 2002
Mon, 12 Aug 2002 18:23:45 -0400
Use getdate( ) or localtime( ) if you want time parts:
$now_1 = getdate( );
$now_2 = localtime( );
print "$now_1[hours]:$now_1[minutes]:$now_1[seconds]";
print "$now_2[2]:$now_2[1]:$now_2[0]";
18:23:45
18:23:45
 
Finding the Difference of Two Dates? 
ans-
Convert both dates to epoch timestamps and subtract one from the other. Use this code to separate the difference into weeks, days, hours, minutes, and seconds:

$epoch_1 = mktime(19,32,56,5,10,1965);
 $epoch_2 = mktime(4,29,11,11,20,1962);
 $diff_seconds = $epoch_1 - $epoch_2;
$diff_weeks = floor($diff_seconds/604800);


How I can get IP address?
ans-getenv("REMOTE_ADDR");

How to store binary data in MySQL?
ans-Use BLOB data type for the database field.

What is CAPTCHA?
ans-CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans
 Apart. To prevent spammers from using bots to automatically fill out forms,
 CAPTCHA programmers will generate an
image containing distorted images of a string of numbers and letters.

What is the difference between sizeof($array) and count($array)?
ans-sizeof($array) - This function is an alias of count()
count($array) - If you just pass a simple variable instead of an array it will return 1.

What is the difference between the functions unlink and unset?
ans-
unlink is a function for file system handling. It will simply delete the file in context.
unset will set UNSET the
specified variable.
unlink is used to delete a file. unset is used to destroy an earlier declared variable.


What is the difference between echo and print?
ans-
echo displays multiple statements and variables but print only
  print is function it returns a value.

What is the default session time in php?
The default session time in php is until closing of browser



PHP?

PHP (Hyper text Pre Processor) is a scripting language commonly used for web applications

in_array() function in php?

It  checks if a value exists in an array

calculate the sum of values in an array ?

array_sum method can calculate sum of values in an array

How we know browser properties?

echo $_SERVER['HTTP_USER_AGENT'];

$browser = get_browser();
foreach ($browser as $name => $value) {
echo “$name $value
\n”;
}

get_browser   returns the capabilities of the user's browser.

What is CAPTCHA?

CAPTCHA stands for Completely Automated Public Turing Test
to tell Computers and Humans  Apart.the application can be fairly
 assured that there is a human client using it.

magic methods?

Magic methods are the members functions that is available to all the instance of class Magic methods always starts with “__”. Eg. __construct All magic methods needs to be declared as public


What is CURL?

CURL stands for Client URL Library.

CURL allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

What is triggers?

A trigger is a database object which is associated with particular database table.
Triggers gets called automatically when particular event(INSERT, UPDATE, DELETE)
occurs on table.

What is LAMP?

LAMP means combination of Linux, Apache, MySQL and PHP.

How get the value of current session id?

Session_id() returns the session id for the current session.

How register the variables into a session?

session_register ($session_var) function.

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

magic_quotes_gpc, magic_quotes_runtime

Magic quotes is the name of a PHP feature that automatically quotes input
data, by using the addslashes() function. Historically, this was used so that
form data could be used directly in SQL queries without any security or quoting
issues. Today, form data is used for much more, and magic quotes quickly
get in the way. We recommend that you disable this feature, but portable code
must be aware of these settings and deal with them appropriately by calling
stripslashes() on GPS (GET, POST, and cookie) data.

Associative Arrays?

You can use string values as keys. For example, you might create an array
like this:

$myStuff = array();
$myStuff[“name”] = “andy”;
$myStuff[“email”] = “andy@fsdsd.ca”;
Print $myStuff[“name”];

Associative arrays are different than normal (numeric-indexed) arrays in
some subtle but important ways:
The order is undefined. Regular arrays are always sorted based on the
numeric index. You don’t know what order an associative array will be
because the keys aren’t numeric.

 You must specify a key. If you’re building a numeric-indexed array, PHP
can always guess what key should be next. This isn’t possible with an
associative array.

 Associative arrays are best for name-value pairs. Associative arrays are
used when you want to work with data that comes in name/value pairs.
This comes up a lot in PHP and XHTML. XHTML attributes are often in
this format, as are CSS rules and form input elements.

✦ Some of PHP’s most important values are associative arrays. The $_
REQUEST variable (described in Chapter 3 of this minibook) is an important
associative array. So are $_GET, $_POST, and several others.

Make sure to include quotation marks if you’re using a string as an array
index.

$_GET , $_POST,$_COOKIE??

$_GET contains any variables provided to a script through the GET method.
 $_POST contains any variables provided to a script through the POST method.
 $_COOKIE contains any variables provided to a script through a cookie.

What line should you add to the Apache configuration file to ensure that the .php extension is recognized?

This line ensures that Apache will treat files ending with the .php extension as
PHP scripts:
AddType application/x-httpd-php .php

php.ini Basics

After you have compiled or installed PHP, you can still change its behavior
with the php.ini file. On Linux/UNIX systems, the default location for this file is
/usr/local/php/lib or the lib subdirectory of the PHP installation location you
used at configuration time. On a Windows system, this file should be in the PHP
directory or another directory as specified by the value of PHPIniDir in the Apache

What Is a Function?

You can think of a function as an input/output machine. This machine takes the raw
materials you feed it (input) and works with them to produce a product (output). A function
accepts values, processes them, and then performs an action (printing to the browser,
for example), returns a new value, or both.

How do you convert the while statement you created in question 3 into a for statement?

$num = 1;
while ($num <= 49) {
echo $num.”<br />”;
$num += 2;
}