Basic Questions

What's PHP?
The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.

Why PHP?

* Speed -- not only the speed of execution, which is important, but also that it not slow down the rest of the machine. So it should not demand a lot of system resources. PHP integrates well with other software, especially under UNIX's, has a small footprint and when run as an Apache module is already loaded for use. Plus, PHP is a thin wrapper around many operating system calls, so can be very fast.
* Stability -- its no good being fast if the system crashes every few thousand pages. No application is bug free, but having a community of PHP developers and users makes it much harder for bugs to survive for long. Under the hood, PHP uses its own resource management system, and has a sophisticated method for handling variables, making it intrinsically a robust system.
* Security -- the system should be protected from malicious attacks from users, both as programmers and as surfers. PHP provides many levels of security which can be set in the .ini file to the desired level.
* Simplicity -- programmers should be able to start being productive as soon as possible. With PHP, even HTML coders can start integrating PHP into their pages straight away. Programmers with previous experience of C, or even with Javascript can get up to speed very quickly.

Oh, and Connectability (which doesn't start with an 'S'). Because of PHP's modular system of extensions it will interface with many diverse libraries, and adding further extensions is very simple. This allows PHP to make use of specialised working libraries from many different areas, such as encryption, graphics, XML and so on.
Further advantages of PHP.

* PHP will run on (almost) any platform. Using the same code base, PHP can be compiled and built on about 25 platforms, including most UNIXs, Windows(95/98/NT/2000) and Macs. As this uses the same code base, all scripts will run identically, whatever the platform.
* PHP is similar to C. So anyone who has experience with a C-style language will soon understand PHP. In C-style languages we can also include Javascript and Java. In fact, much of PHP's functionality is provided by wrappers around the underlying system calls (such as fread() and strlen()) so C programmers will immediately feel at home.
* PHP is extendible. PHP consists of the core parsing engine (written by Zend), a set of core code modules and then a set of code extensions. This allows programmers two ways of extending PHP to do some special processing, either by writing an extension module and compiling it into the executable, or by creating an executable that can be loaded using PHP's dynamic loading mechanism.
* Lots of HTTP server interfaces. PHP currently will load into Apache, IIS, AOLServer, Roxen and THTTPD. Alternatively, it can be run as a CGI module.
* Lots of database interfaces. PHP currently will work with MySQL, MS SQL, Oracle, Informix, PostgreSQL and many others. These are binary level interfaces, and ODBC is also provided for those situations where the database is not supported.
* And lots of other modules... when a PHP user wants to interface to particular library, then it is easy to write an interface for it, and many have done so, and contributed to the main PHP source repository. So you can find modules for graphics routines, PDF files, Flash movies, Cybercash, calendars, XML, IMAP, POP and a host of others. If the library you need is not supported, you can either write one yourself, or employ your favourite programmer to do it.
* PEAR. The PHP Extension and Add-on Repository. Similar to the CPAN network for Perl, although still in its infancy, the idea of PEAR is to provide a set of PHP scripts that would be installed by default with the PHP installation
* Fast. PHP is normally used an Apache module and this makes it very fast. It is entirely written in C and is quite small, so loads and executes quickly with small memory footprint.
* PHP is Open Source. Almost a religious matter to some people! In purely practical terms, it means that you are not dependent on a manufacturer to fix things that don't work, nor are you forced to pay for upgrades every year to get a working version. Those of us who have waited for Allaire to get something fixed will appreciate this.

What Is a Session?
A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.
There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.
Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

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 know the number of days between two given dates using PHP?
Simple arithmetic:

$date1 = date('Y-m-d');
$date2 = '2006-07-01';
$days = (strtotime() - strtotime()) / (60 * 60 * 24);
echo "Number of days since '2006-07-01': $days";

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 $message and $$message?
Anwser 1:
$message is a simple variable whereas $$message is a reference variable. Example:
$user = 'bob'

is equivalent to

$holder = 'user';
$$holder = 'bob';


Anwser 2:
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 Is a Persistent Cookie?
A persistent cookie is a cookie which is stored in a cookie file permanently on the browser's computer. By default, cookies are created as temporary cookies which stored only in the browser's memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:
• Temporary cookies can not be used for tracking long-term information.
• Persistent cookies can be used for tracking long-term information.
• Temporary cookies are safer because no programs other than the browser can access them.

• Persistent cookies are less secure because users can open cookie files see the cookie

How To Turn On the Session Support?
The session support can be turned on automatically at the site level, or manually in each PHP page script:
• Turning on session support automatically at the site level: Set session.auto_start = 1 in php.ini.
• Turning on session support manually in each page script: Call session_start() funtion.

Explain the ternary conditional operator in PHP?
Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.

What’s the difference between include and require?
It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

How many ways can we get the value of current session id?
session_id() returns the session id for the current session.

How to store the uploaded file to the final location?
move_uploaded_file ( string filename, string destination)

This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.

If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

What is the difference between Reply-to and Return-path in the headers of a mail function?
Reply-to: Reply-to is where to delivery the reply of the mail.

Return-path: Return path is when there is a mail delivery failure occurs then where to delivery the failure notification.

Steps for the payment gateway processing?
An online payment gateway is the interface between your merchant account and your Web site. The online payment gateway allows you to immediately verify credit card transactions and authorize funds on a customer's credit card directly from your Web site. It then passes the transaction off to your merchant bank for processing, commonly referred to as transaction batching

Explain normalization concept?
The normalization process involves getting our data to conform to three progressive normal forms, and a higher level of normalization cannot be achieved until the previous levels have been achieved (there are actually five normal forms, but the last two are mainly academic and will not be discussed).

First Normal Form
The First Normal Form (or 1NF) involves removal of redundant data from horizontal rows. We want to ensure that there is no duplication of data in a given row, and that every column stores the least amount of information possible (making the field atomic).

Second Normal Form
Where the First Normal Form deals with redundancy of data across a horizontal row, Second Normal Form (or 2NF) deals with redundancy of data in vertical columns. As stated earlier, the normal forms are progressive, so to achieve Second Normal Form, your tables must already be in First Normal Form.

Third Normal Form
I have a confession to make; I do not often use Third Normal Form. In Third Normal Form we are looking for data in our tables that is not fully dependant on the primary key, but dependant on another value in the table

What’s the difference between accessing a class method via -> and via ::?
:: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.

What are the advantages and disadvantages of CASCADE STYLE SHEETS?
External Style Sheets
Advantages
Can control styles for multiple documents at once Classes can be created for use on multiple HTML element types in many documents Selector and grouping methods can be used to apply styles under complex contexts

Disadvantages
An extra download is required to import style information for each document The rendering of the document may be delayed until the external style sheet is loaded Becomes slightly unwieldy for small quantities of style definitions

Embedded Style Sheets
Advantages
Classes can be created for use on multiple tag types in the document Selector and grouping methods can be used to apply styles under complex contexts No additional downloads necessary to receive style information

Disadvantage
This method can not control styles for multiple documents at once

Inline Styles
Advantages
Useful for small quantities of style definitions Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods

Disadvantages
Does not distance style information from content (a main goal of SGML/HTML) Can not control styles for multiple documents at once Author can not create or control classes of elements to control multiple element types within the document Selector grouping methods can not be used to create complex element addressing scenarios

What type of inheritance that php supports?
In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'.

How can increase the performance of MySQL select query?
We can use LIMIT to stop MySql for further search in table after we have received our required no. of records, also we can use LEFT JOIN or RIGHT JOIN instead of full join in cases we have related data in two or more tables.

How can we change the name of a column of a table?
MySQL query to rename table: RENAME TABLE tbl_name TO new_tbl_name
or,
ALTER TABLE tableName CHANGE OldName newName.


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)?
When you use the metatag in the header section at the beginning of an HTML Web page, the Web page may still be cached in the Temporary Internet Files folder.

A page that Internet Explorer is browsing is not cached until half of the 64 KB buffer is filled. Usually, metatags are inserted in the header section of an HTML document, which appears at the beginning of the document. When the HTML code is parsed, it is read from top to bottom. When the metatag is read, Internet Explorer looks for the existence of the page in cache at that exact moment. If it is there, it is removed. To properly prevent the Web page from appearing in the cache, place another header section at the end of the HTML document. For example:

What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?
There is at least 3 ways to logon to a remote server:
Use ssh or telnet if you concern with security
You can also use rlogin to logon to a remote server.

Give a regular expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag.
Try this: /href="([^"]*)"/i

How can one use the COM components in php?
The COM class provides a framework to integrate (D)COM components into your PHP scripts.
string COM::COM( string module_name [, string server_name [, int codepage]]) - COM class constructor.

Parameters:

module_name: name or class-id of the requested component.
server_name: name of the DCOM server from which the component should be fetched. If NULL, localhost is assumed. To allow DCOM com, allow_dcom has to be set to TRUE in php.ini.
codepage - specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are CP_ACP, CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP, CP_UTF7 and CP_UTF8.
Usage:
$word->Visible = 1; //open an empty document
$word->Documents->Add(); //do some weird stuff
$word->Selection->TypeText("This is a test…");
$word->Documents[1]->SaveAs("Useless test.doc"); //closing word
$word->Quit(); //free the object
$word->Release();
$word = null;

How many ways we can give the output to a browser?
HTML output
PHP, ASP, JSP, Servlet Function
Script Language output Function
Different Type of embedded Package to output to a browser

What is the default session time in php and how can I change it?
The default session time in php is until closing of browser

What changes I have to do in php.ini file for file uploading?
Make the following line uncomment like:
; Whether to allow HTTP file uploads.
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = C:\apache2triad\temp
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

0 comments: