Magic constants

0 comments
PHP provides a large number of predefined constants to any script which it runs. Many of these constants, however, are created by various extensions, and will only be present when those extensions are available, either via dynamic loading or because they have been compiled in.

There are five magical constants that change depending on where they are used. For example, the value of __LINE__ depends on the line that it's used on in your script. These special constants are case-insensitive and are as follows:


Following are few "magical" PHP constants









NameDescription
__LINE__The current line number of the file.
__FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path whereas in older versions it contained relative path under some circumstances.
__FUNCTION__ The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
__CLASS__ The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
__METHOD__ The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).

Functions In php

0 comments
User-defined functions
A function may be defined using syntax such as the following:

Example : Pseudo code to demonstrate function uses

function foo($arg_1, $arg_2, /* ..., */ $arg_n)
{
echo "Example function.\n";
return $retval;
}
?>



Any valid PHP code may appear inside a function, even other functions and class definitions.

Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.

Tip: You may also want to take a look at the Appendix T.

In PHP 3, functions must be defined before they are referenced. No such requirement exists since PHP 4. Except when a function is conditionally defined such as shown in the two examples below.

When a function is defined in a conditional manner such as the two examples shown. Its definition must be processed prior to being called.

Example : Conditional functions


$makefoo = true;

/* We can't call foo() from here
since it doesn't exist yet,
but we can call bar() */

bar();

if ($makefoo) {
function foo()
{
echo "I don't exist until program execution reaches me.\n";
}
}

/* Now we can safely call foo()
since $makefoo evaluated to true */

if ($makefoo) foo();

function bar()
{
echo "I exist immediately upon program start.\n";
}

?>



Example : Functions within functions

function foo()
{
function bar()
{
echo "I don't exist until foo() is called.\n";
}
}

/* We can't call bar() yet
since it doesn't exist. */

foo();

/* Now we can call bar(),
foo()'s processesing has
made it accessible. */

bar();

?>



All functions and classes in PHP have the global scope - they can be called outside a function even if they were defined inside and vice versa.

PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions.

Note: Function names are case-insensitive, though it is usually good form to call functions as they appear in their declaration.

PHP 3 does not support variable numbers of arguments to functions, although default arguments are supported (see Default argument values for more information). Both are supported, as of PHP 4: see Variable-length argument lists and the function references for func_num_args(), func_get_arg(), and func_get_args() for more information.

It is possible to call recursive functions in PHP. However avoid recursive function/method calls with over 100-200 recursion levels as it can smash the stack and cause a termination of the current script. Example 17-4. Recursive functions

function recursion($a)
{
if ($a < 20) {
echo "$a\n";
recursion($a + 1);
}
}
?>

Visibility

0 comments
The visibility of a property or method can be defined by prefixing the declaration with the keywords: public, protected or private. Public declared items can be accessed everywhere. Protected limits access to inherited and parent classes (and to the class that defines the item). Private limits visibility only to the class that defines the item.

Members Visibility

Class members must be defined with public, private, or protected.
Example : Member declaration
/**
* Define MyClass
*/
class MyClass
{
public $public = 'Public';
protected $protected = 'Protected';
private $private = 'Private';

function printHello()
{
echo $this->public;
echo $this->protected;
echo $this->private;
}
}

$obj = new MyClass();
echo $obj->public; // Works
echo $obj->protected; // Fatal Error
echo $obj->private; // Fatal Error
$obj->printHello(); // Shows Public, Protected and Private


/**
* Define MyClass2
*/
class MyClass2 extends MyClass
{
// We can redeclare the public and protected method, but not private
protected $protected = 'Protected2';

function printHello()
{
echo $this->public;
echo $this->protected;
echo $this->private;
}
}

$obj2 = new MyClass2();
echo $obj->public; // Works
echo $obj2->private; // Undefined
echo $obj2->protected; // Fatal Error
$obj2->printHello(); // Shows Public, Protected2, not Private

?>



Note: The PHP 4 method of declaring a variable with the var keyword is still supported for compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT warning.

Method Visibility

Class methods must be defined with public, private, or protected. Methods without any declaration are defined as public.
Example : Method Declaration

/**
* Define MyClass
*/
class MyClass
{
// Contructors must be public
public function __construct() { }

// Declare a public method
public function MyPublic() { }

// Declare a protected method
protected function MyProtected() { }

// Declare a private method
private function MyPrivate() { }

// This is public
function Foo()
{
$this->MyPublic();
$this->MyProtected();
$this->MyPrivate();
}
}

$myclass = new MyClass;
$myclass->MyPublic(); // Works
$myclass->MyProtected(); // Fatal Error
$myclass->MyPrivate(); // Fatal Error
$myclass->Foo(); // Public, Protected and Private work


/**
* Define MyClass2
*/
class MyClass2 extends MyClass
{
// This is public
function Foo2()
{
$this->MyPublic();
$this->MyProtected();
$this->MyPrivate(); // Fatal Error
}
}

$myclass2 = new MyClass2;
$myclass2->MyPublic(); // Works
$myclass2->Foo2(); // Public and Protected work, not Private

class Bar
{
public function test() {
$this->testPrivate();
$this->testPublic();
}

public function testPublic() {
echo "Bar::testPublic\n";
}

private function testPrivate() {
echo "Bar::testPrivate\n";
}
}

class Foo extends Bar
{
public function testPublic() {
echo "Foo::testPublic\n";
}

private function testPrivate() {
echo "Foo::testPrivate\n";
}
}

$myFoo = new foo();
$myFoo->test(); // Bar::testPrivate
// Foo::testPublic
?>

Constructors and Destructors

0 comments
Constructor

void __construct ( [mixed args [, ...]] )
PHP 5 allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.
Note: Parent constructors are not called implicitly if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required.

Example :using new unified constructors

class BaseClass {
function __construct() {
print "In BaseClass constructor\n";
}
}

class SubClass extends BaseClass {
function __construct() {
parent::__construct();
print "In SubClass constructor\n";
}
}

$obj = new BaseClass();
$obj = new SubClass();
?>


For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named __construct() which was used for different semantics.

Destructor

void __destruct ( void )
PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed.

Example : Destructor Example

class MyDestructableClass {
function __construct() {
print "In constructor\n";
$this->name = "MyDestructableClass";
}

function __destruct() {
print "Destroying " . $this->name . "\n";
}
}

$obj = new MyDestructableClass();
?>


Like constructors, parent destructors will not be called implicitly by the engine. In order to run a parent destructor, one would have to explicitly call parent::__destruct() in the destructor body.

Note: Destructor is called during the script shutdown so headers are always already sent.

Note: Attempting to throw an exception from a destructor causes a fatal error.

File System Functions In php

0 comments
 basename  -- Returns filename component of path ..

 chgrp  -- Changes file group ..

 chmod  -- Changes file mode.

  chown  -- Changes file owner .

 clearstatcache  -- Clears file status cache .

 copy  -- Copies file .

 delete  -- See unlink() or unset() .

 dirname  -- Returns directory name component of path .

 disk_free_space  -- Returns available space in directory .

 disk_total_space  -- Returns the total size of a directory .

 diskfreespace  -- Alias of disk_free_space() .

 fclose  -- Closes an open file pointer.

  feof  -- Tests for end-of-file on a file pointer.

  fflush  -- Flushes the output to a file .

 fgetc  -- Gets character from file pointer.

  fgetcsv  -- Gets line from file pointer and parse for CSV fields.

  fgets  -- Gets line from file pointer.

  fgetss  -- Gets line from file pointer and strip HTML tags.

  file_exists  -- Checks whether a file or directory exists.

  file_get_contents  -- Reads entire file into a string.

  file_put_contents  -- Write a string to a file .

 file  -- Reads entire file into an array .

 fileatime  -- Gets last access time of file .

 filectime  -- Gets inode change time of file.

  filegroup  -- Gets file group.

  fileinode  -- Gets file inode.

  filemtime  -- Gets file modification time .

 fileowner  -- Gets file owner.

  fileperms  -- Gets file permissions.

  filesize  -- Gets file size.

  filetype  -- Gets file type.

  flock  -- Portable advisory file locking .

 fnmatch  -- Match filename against a pattern.

  fopen  -- Opens file or URL.

  fpassthru  -- Output all remaining data on a file pointer.

  fputcsv  -- Format line as CSV and write to file pointer.

  fputs  -- Alias of fwrite().

 fread  -- Binary-safe file read.

  fscanf  -- Parses input from a file according to a format.

  fseek  -- Seeks on a file pointer .

 fstat  -- Gets information about a file using an open file pointer.

  ftell  -- Tells file pointer read/write position .

 ftruncate  -- Truncates a file to a given length .

 fwrite  -- Binary-safe file write .

 glob  -- Find pathnames matching a pattern.

  is_dir  -- Tells whether the filename is a directory.

  is_executable  -- Tells whether the filename is executable.

  is_file  -- Tells whether the filename is a regular file.

  is_link  -- Tells whether the filename is a symbolic link .

 is_readable  -- Tells whether the filename is readable.

  is_uploaded_file  -- Tells whether the file was uploaded via HTTP POST.

  is_writable  -- Tells whether the filename is writable.

  is_writeable  -- Alias of is_writable().

 lchgrp  -- Changes group ownership of symlink.

  lchown  -- Changes user ownership of symlink.

  link  -- Create a hard link.

  linkinfo  -- Gets information about a link.

  lstat  -- Gives information about a file or symbolic link.

  mkdir  -- Makes directory .

 move_uploaded_file  -- Moves an uploaded file to a new location .

 parse_ini_file  -- Parse a configuration file.

  pathinfo  -- Returns information about a file path .

 pclose  -- Closes process file pointer .

 popen  -- Opens process file pointer.

  readfile  -- Outputs a file.

  readlink  -- Returns the target of a symbolic link .

 realpath  -- Returns canonicalized absolute pathname.

  rename  -- Renames a file or directory .

 rewind  -- Rewind the position of a file pointer .

 rmdir  -- Removes directory .

 set_file_buffer  -- Alias of stream_set_write_buffer().

 stat  -- Gives information about a file .

 symlink  -- Creates a symbolic link .

 tempnam  -- Create file with unique file name.

 tmpfile  -- Creates a temporary file .

 touch  -- Sets access and modification time of file.

  umask  -- Changes the current umask .

 unlink  -- Deletes a file.
0 comments
How can we get second of the current time using date function?
$second = date("s");

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 I make a script that can be bilingual (supports English, German)?
You can change charset variable in above line in the script to support bilanguage.

What are the difference between abstract class and interface?
Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.

Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

What are the advantages of stored procedures, triggers, indexes?
A stored procedure is a set of SQL commands that can be compiled and stored in the server. Once this has been done, clients don't need to keep re-issuing the entire query but can refer to the stored procedure. This provides better overall performance because the query has to be parsed only once, and less information needs to be sent between the server and the client. You can also raise the conceptual level by having libraries of functions in the server. However, stored procedures of course do increase the load on the database server system, as more of the work is done on the server side and less on the client (application) side. Triggers will also be implemented. A trigger is effectively a type of stored procedure, one that is invoked when a particular event occurs. For example, you can install a stored procedure that is triggered each time a record is deleted from a transaction table and that stored procedure automatically deletes the corresponding customer from a customer table when all his transactions are deleted. Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to read sequentially, because this minimizes disk seeks.

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

How can we destroy the cookie?
Set the cookie with a past expiration time.

What are the current versions of Apache, PHP, and MySQL?
PHP: PHP 5.1.2
MySQL: MySQL 5.1
Apache: Apache 2.1

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.

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.

What is the use of friend function?
Friend functions
Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class.
A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.
class mylinkage
{
private:
mylinkage * prev;
mylinkage * next;

protected:
friend void set_prev(mylinkage* L, mylinkage* N);
void set_next(mylinkage* L);

public:
mylinkage * succ();
mylinkage * pred();
mylinkage();
};

void mylinkage::set_next(mylinkage* L) { next = L; }

void set_prev(mylinkage * L, mylinkage * N ) { N->prev = L; }

Friends in other classes
It is possible to specify a member function of another class as a friend as follows:
class C
{
friend int B::f1();
};
class B
{
int f1();
};

It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.
class A
{
friend class B;
};

Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when using the operator overloading features of C++. We will return to it when we look at overloading.

Tools used for drawing ER diagrams.
Case Studio
Smart Draw

How can I know that a variable is a number or not using a JavaScript?
Answer 1:
bool is_numeric( mixed var)
Returns TRUE if var is a number or a numeric string, FALSE otherwise.

Answer 2:
Definition and Usage
The isNaN() function is used to check if a value is not a number.

Syntax
isNaN(number)

Parameter Description
number Required. The value to be tested

How can we submit from without a submit button?
Trigger the JavaScript code on any event ( like onSelect of drop down list box, onfocus, etc ) document.myform.submit(); This will submit the form.

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

DataBase Issues with php

0 comments
1. I heard it's possible to access Microsoft SQL Server from PHP. How?
On Windows machines, you can simply use the included ODBC support and the correct ODBC driver.
On Unix machines, you can use the Sybase-CT driver to access Microsoft SQL Servers because they are (at least mostly) protocol-compatible. Sybase has made a free version of the necessary libraries for Linux systems. For other Unix operating systems, you need to contact Sybase for the correct libraries. Also see the answer to the next question.

2. Can I access Microsoft Access databases?
Yes. You already have all the tools you need if you are running entirely under Windows 9x/Me, or NT/2000, where you can use ODBC and Microsoft's ODBC drivers for Microsoft Access databases.
If you are running PHP on a Unix box and want to talk to MS Access on a Windows box you will need Unix ODBC drivers. OpenLink Software has Unix-based ODBC drivers that can do this.
Another alternative is to use an SQL server that has Windows ODBC drivers and use that to store the data, which you can then access from Microsoft Access (using ODBC) and PHP (using the built in drivers), or to use an intermediary file format that Access and PHP both understand, such as flat files or dBase databases. On this point Tim Hayes from OpenLink software writes:
Using another database as an intermediary is not a good idea, when you can use ODBC from PHP straight to your database - i.e. with OpenLink's drivers. If you do need to use an intermediary file format, OpenLink have now released Virtuoso (a virtual database engine) for NT, Linux and other Unix platforms. Please visit our website for a free download.
One option that has proved successful is to use MySQL and its MyODBC drivers on Windows and synchronizing the databases. Steve Lawrence writes:
Install MySQL on your platform according to instructions with MySQL. Latest available from http://www.mysql.com/ No special configuration required except when you set up a database, and configure the user account, you should put % in the host field, or the host name of the Windows computer you wish to access MySQL with. Make a note of your server name, username, and password.
Download the MyODBC for Windows driver from the MySQL site. Install it on your Windows machine. You can test the operation with the utilities included with this program.
Create a user or system dsn in your ODBC administrator, located in the control panel. Make up a dsn name, enter your hostname, user name, password, port, etc for you MySQL database configured in step 1.
Install Access with a full install, this makes sure you get the proper add-ins... at the least you will need ODBC support and the linked table manager.
Now the fun part! Create a new access database. In the table window right click and select Link Tables, or under the file menu option, select Get External Data and then Link Tables. When the file browser box comes up, select files of type: ODBC. Select System dsn and the name of your dsn created in step 3. Select the table to link, press OK, and presto! You can now open the table and add/delete/edit data on your MySQL server! You can also build queries, import/export tables to MySQL, build forms and reports, etc.

Tips and Tricks:
You can construct your tables in Access and export them to MySQL, then link them back in. That makes table creation quick.

When creating tables in Access, you must have a primary key defined in order to have write access to the table in access. Make sure you create a primary key in MySQL before linking in access

If you change a table in MySQL, you have to re-link it in Access. Go to tools>add-ins>linked table manager, cruise to your ODBC DSN, and select the table to re-link from there. you can also move your dsn source around there, just hit the always prompt for new location checkbox before pressing OK.

3. I upgraded to PHP 4, and now mysql keeps telling me "Warning: MySQL: Unable to save result set in ...". What's up?
Most likely what has happened is, PHP 4 was compiled with the --with-mysql option, without specifying the path to MySQL. This means PHP is using its built-in MySQL client library. If your system is running applications, such as PHP 3 as a concurrent Apache module, or auth-mysql, that use other versions of MySQL clients, then there is a conflict between the two differing versions of those clients.
Recompiling PHP 4, and adding the path to MySQL to the flag, '--with-mysql=/your/path/to/mysql' usually solves the problem.

4. PHP 5 no longer bundles MySQL client libraries, what does this mean to me? Can I still use MySQL with PHP? I try to use MySQL and get "function undefined" errors, what gives?
Yes. There will always be MySQL support in PHP of one kind or another. The only change in PHP 5 is that we are no longer bundling the client library itself. Some reasons in no particular order:
Most systems these days already have the client library installed.
Given the above, having multiple versions of the library can get messy. For example, if you link mod_auth_mysql against one version and PHP against another, and then enable both in Apache, you get a nice fat crash. Also, the bundled library didn't always play well with the installed server version. The most obvious symptom of this being disagreement over where to find the mysql.socket Unix domain socket file.
Maintenance was somewhat lax and it was falling further and further behind the released version.
Future versions of the library are under the GPL and thus we don't have an upgrade path since we cannot bundle a GPL'ed library in a BSD/Apache-style licensed project. A clean break in PHP 5 seemed like the best option.
This won't actually affect that many people. Unix users, at least the ones who know what they are doing, tend to always build PHP against their system's libmyqlclient library simply by adding the --with-mysql=/usr option when building PHP. Windows users may enable the extension php_mysql.dll inside php.ini. For more details, see the MySQL Reference for installation instructions. Also, be sure libmysql.dll is available to the systems PATH. For more details on how, read the FAQ on setting up the Windows systems PATH. Because libmysql.dll (and many other PHP related files) exist in the PHP folder, you'll want to add the PHP folder to your systems PATH.

5. After installing shared MySQL support, Apache dumps core as soon as libphp4.so is loaded. Can this be fixed?
If your MySQL libs are linked against pthreads this will happen. Check using ldd. If they are, grab the MySQL tarball and compile from source, or recompile from the source rpm and remove the switch in the spec file that turns on the threaded client code. Either of these suggestions will fix this. Then recompile PHP with the new MySQL libs.

6. Why do I get an error that looks something like this: "Warning: 0 is not a MySQL result index in on line " or "Warning: Supplied argument is not a valid MySQL result resource in on line "?

You are trying to use a result identifier that is 0. The 0 indicates that your query failed for some reason. You need to check for errors after submitting a query and before you attempt to use the returned result identifier. The proper way to do this is with code similar to the following:

$result = mysql_query("SELECT * FROM tables_priv");
if (!$result) {
echo mysql_error();
exit;
}
?>
or
$result = mysql_query("SELECT * FROM tables_priv")
or die("Bad query: " . mysql_error());
?>

Basic Questions

0 comments
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