Skip to main content

Openings for different technoogies.

PHP Interview questions 2

1) How we load all classes that placed in different directory in one PHP File , means how to do auto load classes
Ans :      by using spl_autoload_register('autoloader::funtion');
Like below
class autoloader
{
public static function moduleautoloader($class)
{
$path = $_SERVER['DOCUMENT_ROOT'] . "/modules/{$class}.php";
if (is_readable($path)) require $path;
}
public static function daoautoloader($class)
{
$path = $_SERVER['DOCUMENT_ROOT'] . "/dataobjects/{$class}.php";
if (is_readable($path)) require $path;
}
public static function includesautoloader($class)
{
$path = $_SERVER['DOCUMENT_ROOT'] . "/includes/{$class}.php";
if (is_readable($path)) require $path;
}
}
spl_autoload_register('autoloader::includesautoloader');
spl_autoload_register('autoloader::daoautoloader');
spl_autoload_register('autoloader::moduleautoloader');

2) How many types of Inheritances used in PHP and how we achieve it
Ans :      As far PHP concern it only support single Inheritance in scripting.
we can also use interface to achieve multiple inheritance.
                 
3)          PHP how to know user has read the email?
Ans :      Using Disposition-Notification-To: in mailheader we can get read receipt.
Add the possibility to define a read receipt when sending an email.
It’s quite straightforward, just edit email.php, and add this at vars definitions:
var $readReceipt = null;
And then, at ‘createHeader’ function add:
if (!empty($this->readReceipt)) {
$this->__header .= ‘Disposition-Notification-To: ‘ . $this->__formatAddress($this->readReceipt) . $this->_newLine;
}

4) What are default session time and path?
Ans :      default session time in PHP is 1440 seconds or 24 minutes
Default session save path id temporary folder /tmp

5) how to track user logged out or not? when user is idle ?
Ans : 85                By checking the session variable exist or not while loading th page. As the session will exist longer as till browser closes. The default behaviour for sessions is to keep a session open indefinitely and only to expire a session when the browser is closed. This behaviour can be changed in the php.ini file by altering the line session.cookie_lifetime = 0 to a value in seconds. If you wanted the session to finish in 5 minutes you would set this to session.cookie_lifetime = 300 and restart your httpd server.

6) What is the difference between char and varchar data types?
Ans :      Set char to occupy n bytes and it will take n bytes even if u r storing a value of n-m bytes
Set varchar to occupy n bytes and it will take only the required space and will not use the n bytes
eg. name char(15) will waste 10 bytes if we store 'romharshan', if each char takes a byte eg. name varchar(15) will just use 5 bytes if we store 'romharshan', if each char takes a byte. rest 10 bytes will be free.

7) What is the functionality of md5 function in PHP?
Ans :      Calculate the md5 hash of a string. The hash is a 32-character hexadecimal number. I use it to generate keys which I use to identify users etc. If I add random no techniques to it the md5 generated now will be totally different for the same string I am using.

8) How can I load data from a text file into a table?
Ans :      you can use LOAD DATA INFILE file_name; syntax to load data from a text file. but you have to make sure thata) data is delimited
b) columns and data matched correctly

9) How can we know the number of days between two given dates using MySQL?
Ans :      SELECT DATEDIFF("2007-03-07","2005-01-01");
                 
10) How can we know the number of days between two given dates using PHP?
Ans :      $date1 = date("Y-m-d");
$date2 = "2006-08-15";
$days = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24);

Comments

Popular posts from this blog

Openings for different technoogies.

 

We are Hiring Mobile Engineer Lead

Experience required for the Job: 8 - 10 years Job Location: Bengaluru/Bangalore Invensys Skelta is looking for Lead Mobile app engineers to drive the mobile strategy globally for its multiple products. The candidate should be enthusiastic to further the knowledge of cross-platform and multi-platform development and who makes things happen. Successful candidate will work closely with the project managers and development team globally to develop ideas, concepts, and solutions for mobile apps that help the brand meet their objectives. Person Specification: *    An expert in either iOS, Android or Windows Phone 8 *    Passion for Research & Development, and believes in simple, intuitive and scalable mobile applications that can help solve some of the biggest and complex problems *    An interest in techniques for producing portable cross-platform code and an attention to detail in all aspects of the development process; whether it"s making yo...

Looking for Drupal Themer

Location : Bangalore Position : Drupal Themer Job Responsibilities: • Work with Drupal Developer in porting pages to Drupal • Responsible for building Drupal themes and template files for themes for requirements specified Preferred profile: Strong Knowledge of Drupal coding standards. Strong grasp of semantic, HTML and CSS based design • Experience in converting PSDs and into functional Drupal themes from scratch • Experience in creating well-commented, Zen-based subthemes (http://drupal.org/project/zen) from provided layered Photoshop compositions, including creating and editing templates for different node-types and pages, editing .info files, and adding additional theme settings using the Drupal Form API. • Experience in adding, editing and deleting pages, users, user groups, blocks, and block areas on a pre-existing Drupal installation based on provided directions, text, pictures and wireframes • Experience in testing and modifying Drupal themes and stylesheets to ensure consistent...